View Full Version : JPEG Compression to a fixed size
Eastermeyer
31st December 2006, 13:21
Hi!
Do you know a Tool , which can compress a BMP to a JPEG-Image at an specific filesize ?
foxyshadis
31st December 2006, 13:42
Command-line or GUI? And if GUI, how interactive? (like, do you want to just punch in a size and let it go, or would you prefer to have a slider and a preview window you could tweak until it gives the right size?)
Eastermeyer
31st December 2006, 14:02
GUI or CLI , that doesn't matter , i am able to use both
How interactive ?
Punch in some files , set the output filesize and hit "go". That would be optimal.
stegre
31st December 2006, 20:21
I assume you mean "getting a given filesize" by changing the compression ratio, not the resulting image size, right?
Paint Shop Pro ($), and XnView (http://www.xnview.com/), which is free, both have options where you type in the filesize - they then convert the source format it adjust target compression ratio for the filesize you typed in. And both will "batch convert" as many pics as you want that way with one click -- BUT -- both have that for JPEG2000 only, not for regular JPG. There must be something different about the JPEG2000 file format that makes that easier.
With Paint Shop Pro you can do it for regular JPEG images one by one, but it's not exactly "one-click". When you choose "save as JPG" you hit "options" you get to the compression ration setting, but you get the more common 1 thru 100 "quality" slider only, not way to specify filesize. But if you then hit "run optimizer" you can manually adjust the slider & see a preview and the filesize you're gonna get, so you'd have to slide it back and forth until you see the filesize you want, then hit OK. I don't think XnView has that, though.
The JPEG2000 feature works great though - I just tried it on XnView & set it to 100K, tested it with 10 files and within a few seconds I had 10 *.JP2 files all between 99.6KB and 99.9KB - none went over; I think they treat it as an upper limit and seem to get to with one-half percent of it every time, usually even closer. But if you need regular JPG's, that's not gonna help you, unfortunately.
joseph5
31st December 2006, 21:24
With Paint Shop Pro you can do it for regular JPEG images one by one, but it's not exactly "one-click". When you choose "save as JPG" you hit "options" you get to the compression ration setting, but you get the more common 1 thru 100 "quality" slider only, not way to specify filesize. But if you then hit "run optimizer" you can manually adjust the slider & see a preview and the filesize you're gonna get, so you'd have to slide it back and forth until you see the filesize you want, then hit OK. I don't think XnView has that, though.
The Gimp(free) also has this feature.
foxyshadis
1st January 2007, 08:10
It's because j2k works differently from jpeg - it's a 100% streaming format, where every extra byte (well, multi-byte packet) you have nets you extra detail somewhere, from nothing all the way to lossless. Specifying a quality just maps onto a size ratio.
Standard jpeg is block-tiled and nothing like that, and progressive jpeg only has 3-5 layers; if you could interleave all 64, or better yet slice the individual quants into 2 or 4 bit chunks (giving 128 or 256 layers) you could have the granulatity of j2k, at some increased computational cost. But that's all theoretical, since no one would do such a thing at this point. ^^;
Back on topic, I looked, but the one tool I knew of that did size had a very annoying one-file-at-a-time gui. I think the only solution might be to script something around imagemagick that'll keep trying different qualities until it hits the right size.
stegre
1st January 2007, 17:44
I think the only solution might be to script something around imagemagick that'll keep trying different qualities until it hits the right size.
Yeah, that sounds like the same answer a forum admin gave to someone who asks what sounds like this exact same question in the ImageMagick forum (http://www.imagemagick.org/discourse-server/viewtopic.php?p=24696). He seems to imply that you could measure the image size in memory without actually writing it out over and over, I guess to speed things up, but it sounds like it'd still be a trial and error type script. I'm not familiar with ImageMagick in any particular detail so I can't really comment further beyond what's stated in the thread.
setarip_old
1st January 2007, 18:30
@Eastermeyer
Hi!
Although I have no advice to offer to you, I do have a question:
Why do you need/want to have your images of the same filesize (e.g. 3,000 kilobytes)?
Or, as was asked in an earlier post to this thread, do you actually want to have your images of the same dimensions (e.g. 640x480)? ....
jon.schaffer
1st January 2007, 22:41
I'm quite sure that QuickTime Pro offers/-ed (?) this option. I used it in the past (QT 4, 5 or 6 at that time? Don't remember).
You could load an image sequence and export it that way.
The process was quite long (maybe the program has to test different levels of compression to achieve the desired filesize since filesize is unpredictable. Just a guess though).
JS
Edit: the final filesize will not always be exactly the same - it may be simply impossible to achieve it.
stegre
2nd January 2007, 05:46
@Eastermeyer
....Or, as was asked in an earlier post to this thread, do you actually want to have your images of the same dimensions (e.g. 640x480)?
That was me, though that wasn't exactly what I asked, since his original question was phrased "compress a BMP to a JPEG-Image at an specific filesize" I figured that part of his question was clear (and a there are probably dozens of apps that will resize images to identical target dimensions). What he didn't clarify, however was whether the question was "How do I adjust the dimensions to achieve a specific filesize?" vs. "How do I adjust the compression ratio to achieve a specific filesize?". The remainder of the thread was addressing the latter question, although he still hasn't actually made the answer to that clear.
@Eastermeyer
Why do you need/want to have your images of the same filesize (e.g. 3,000 kilobytes)?....
I was kinda wondering that myself...
Eastermeyer
5th January 2007, 16:03
Tried out Quicktime , and yes it has got the feature but it makes bad results , i set to 1mb and it outputs 60kb.
setarip_old
5th January 2007, 18:25
@Eastermeyer
I'd ask again, why do you need/want to have your images of the same filesize (e.g. 3,000 kilobytes)?....
Eastermeyer
5th January 2007, 19:33
On our school file system there are some size limitations.
In i would like to get the best quality possible without trial and error.
gameplaya15143
5th January 2007, 21:36
Size limitations? What kind? Per-file size limitation? or total-space size limitation?
If it's per-file size limitation, I would just use a file splitter like KFK (http://primus.tucows.com/preview/196049.html) on the bitmap.
For compressing a jpg based on filesize, I think the brute force method is the only one that exists. You might be able to write a script and use a command line program to do the messy part for you.
Good luck.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.