Click to See Complete Forum and Search --> : How to compress a JPEG image for the web?


HughA
04-21-2006, 02:59 AM
I have a JPEG image of around 60KB, and I am looking for the simplest way of compressing this in order to serve it over the web. Does anyone have any ideas on how this might best be accomplished - perhaps with either the ImageMagick suite or GIMP?

Thanks,
Hugh

Parcival
04-21-2006, 03:17 AM
The file size of an image is affected by its dimensions and its format.

Most of the time the factor that brings the most dramatic reduction in volume is to shrink the picture to smaller dimensions. You can do this in the Gimp with the menue Image/Scale.

The second factor is the file format. For this to work effectively, you need to know a little about what advantages these file formats offer:

JPEG reduces the data volume by calculating means between color values. That's why JPEG is good for photographs or any picture that comes with lots of colors. It isn't really good for logos or simple graphics in generals because it can lead to so called pixel clouds that look ugly.

GIF/PNG reduce the volume by limiting the number of colors. This is especially useful for logos and simple graphics that were drawn with few colors in the first place. If applied to a photograph, the photograph will most likely look very dull as it looses its virulent colors.

HughA
04-21-2006, 05:09 AM
Thanks Parcival,

I'll try reducing the size of the image in GIMP to see how I go.

Regards,
Hugh

rocketpcguy
04-21-2006, 05:23 AM
PNG reduce the volume by limiting the number of colors...If applied to a photograph, the photograph will most likely look very dull as it looses its virulent colors

i thought png was lossless, and can be an exact copy of the original image? you mean if i save my bmp photo files to png, it becomes/looks different?

Parcival
04-21-2006, 03:41 PM
i thought png was lossless, and can be an exact copy of the original image?

The GIF format has the 256 colors barrier which got removed when the PNG format was created. However, if you save a BMP file as PNG without any reduction in colors, you won't get any compression benefits.

cybertron
04-21-2006, 08:38 PM
Hmm, I'm going to have to disagree. PNG was designed specifically to be able to compress 24-bit images and do it better and with no stupid restrictions like GIF. BMP has almost no compression at all (just run length encoding for repeated sections of color) so it is always a larger size. For instance, I saved an image as a 24 bit BMP and a 24 bit PNG and they came out to be 901k and 135k respectively. Granted, it was a gradient which PNG compresses extremely well, but in general you still get very good compression with PNG.

Speaking of gradients that compress extremely well, here's (http://www.libpng.org/pub/png/img_png/16million-pschmidt.png) a good example. It's 4096x4096 and contains every possible color in a 24 bit image. It's only 60k. :eek:

From here: http://www.libpng.org/pub/png/pngintro.html

Anyway, the problem with using PNG for photographic images is that it's very difficult to losslessly compress them because there aren't any patterns to combine. You'll get a lossless image, but it's going to be much larger than the JPEG of almost as good a quality so it's not really worth it. BMP will be larger still.

bwkaz
04-21-2006, 08:45 PM
Yes, you will get a size decrease. I fired up GIMP and exported backgrounds/0011.png to a BMP file. This is what came out:

$ ls -l backgrounds/0011.*
-rw-r--r-- 1 me me 3932214 Apr 21 19:40 backgrounds/0011.bmp
-rw-r--r-- 1 me me 257194 Sep 14 2005 backgrounds/0011.png Notice how the BMP file is approximately 16 times larger, and it came from the PNG (so there can't be more colors in it).

PNG gets its compression from zlib (if I understand correctly, it basically compresses the entire set of pixels using zlib at the highest compression level). So the more repeated data you have (the more pixels that are exactly the same color), the better it will compress -- which is why pictures don't compress well with PNG. It's not that they look worse as a PNG, it's that they're bigger than they would be as a JPEG. (Whereas for simple images -- charts, etc.; stuff that has large areas of one color -- PNG and JPEG are about the same size, but PNG doesn't have the artifacts that JPEG does.) PNG is actually lossless.

EnigmaOne
04-22-2006, 02:55 AM
Interesting convo....

I just compared three verisions of the scan of the marriage record for my wife and myself...

example.user@1[example.folder]$ ls -l
total [irrelevant]
-rw-r--r-- 1 example.user example.user 11193654 2006-04-21 22:56 MarriageRecord.bmp
-rw-r--r-- 1 example.user example.user 4060488 2006-04-21 23:02 MarriageRecord.jpg
-rw-r--r-- 1 example.user example.user 1048576 2006-04-21 22:56 MarriageRecord.png
example.user@1[example.folder]$

DSwain
04-22-2006, 02:44 PM
If I remember correctly, when you're saving files with GIMP, you can change the level of quality (at least with PNGs) which should help reduce size. I'm sure you may be able to find a compromise between quality and quantity by doing something like this, though may quality isn't worth the sacrafice.

rocketpcguy
04-22-2006, 03:51 PM
you can change the level of quality (at least with PNGs)

quality? if its lossless, wouldnt that mean there is no quality (just the exact image)? i thought the compression level in gimp was for speed/size, not quality/size?

DSwain
04-22-2006, 04:09 PM
quality? if its lossless, wouldnt that mean there is no quality (just the exact image)? i thought the compression level in gimp was for speed/size, not quality/size?

Sorry, I didn't check the dialog before I posted. You can change the compression level of it (from 0-9 I suppose it is) via GIMP, not quality. I must be thinking of something else for quality.

While we're on the topic, I checked jpg and that allows you to change the quality, while png allows you to change the compression level. I imagine, though, that changing the compression level of a png will still make the png have a certain quality to it, but don't take my word for that.

cybertron
04-22-2006, 10:44 PM
quality? if its lossless, wouldnt that mean there is no quality (just the exact image)? i thought the compression level in gimp was for speed/size, not quality/size?
Yep, it's just for speed. It's the same as setting the compression level on a zip file. It doesn't throw away any of your data, it just compresses it more with a corresponding increase in the amount of CPU it takes to de/compress it.

Parcival
04-23-2006, 06:52 AM
I just compared three verisions of the scan of the marriage record for my wife and myself...

You must have the marriage plugin enabled in your Gimp. It renders your png files to what you thought marriage was when you proposed, your jpg files to what was dooming in your head on the day of the wedding, and the bmp to what it feels like when you have to get five kids ready for school, your car has hickups on your way back from getting a ton of groceries that would feed Cesar's entire Legions, and your mother-in-law has announced she will come for a visit in three days.

Hmmm, who still wants to claim that free software doesn't meet the needs of the average user?

HughA
04-27-2006, 09:25 AM
# ls -l source.jpg
# display source.jpg
# convert -colors <n> -quality <n> source.jpg target.jpg
# ls -l target.jpg
# display target.jpg