Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Most image formats are already compressed. But in fact, if I take an image and compress it [gzipping it], and then I compare the compressed one to the uncompressed one, there is a difference in size, even though not such a dramatic difference.

The question is: is it worth gzipping images? the content size flushed down to the client's browser will be smaller, but there will be some client overhead when de-gzipping it.

Please advise.

share|improve this question

migrated from stackoverflow.com Jan 27 '11 at 22:42

This question came from our site for professional and enthusiast programmers.

1  
If your server bottleneck is closer on network than on CPU, sure. Else, there might be lower hanging fruit. –  Konerak Jan 27 '11 at 20:18

5 Answers 5

This would depend on what is more important, client decompression resources (time, processing power, memory, etc.) or network bandwidth.

Example 1) Your client systems are either very close to the server (say on a local network) or have high speed connections, however they are very low powered (perhaps embedded systems with limited resources). You would NOT want any client side overhead (un-gziping) and could easily afford the transfer overhead (a few bytes makes no difference in the real world on a local network).

Example 2) Your clients are all very high powered systems (say, above average office workstations) however there are thousands of them and your server only has a limited bandwidth allocation. In this scenario the end users can easily afford the overhead and every byte matters to the server. gzip away!

Real World) You are likely NOT better off gziping your images. Modern systems can well afford the processing however, if you have real world expectations someone will use a cell phone or other low powered system. Additionally you are imposing the restriction that the receiver be able to un-gzip. Shouldn't be a problem most of the time, but why limit anyone? The size savings will be trivial and the processing overhead will not be for any system. The greater the size savings you should expect even greater processor overhead so any time you save in the transfer over any normal type of connection has a chance to just be re-created by the time taken to process the gzip into something usable.

Your best bet IMO is to look into higher optomization and alternative image formats. Not all JPEGs are created equal. Example: save an image as a jpeg in photoshop, then "save for web and devices" as jpeg, the file size should be drastically different with the same quality settings. Additionally the "save for" option provides many more options for fine tuning quality and file size. Don't be afraid of more "dated" formats like GIFs as well. If your image displays nicely within the limitations of the GIF format it's likely to be much smaller still, and offer extra benefits like transparency...

share|improve this answer
    
Thanks for your detailed response. The scenario I'm talking about is a scenario that involves millions of existing images, partially optimized, on an e-commerce website. So it is clear, that the highest priority is quick rendering at the client side, and that the clients' machines are average-and-less powered. Saving in a different format is not an option [huge investment]. The best solution would be in a case like this [so many existing images], to have a tool that could optimize all jpeg files in a folder. Are you familiar with such a tool? –  charlie Jan 27 '11 at 22:37
    
There's a free command line utility called jpegtran which optimizes JPEGs, it might be able to batch process all images in a folder so that might be worth investigating. –  Tim Fountain Jan 28 '11 at 11:46

Google makes reference to gzip and image/binary files at Minimize payload size

Don't use gzip for image or other binary files.

Image file formats supported by the web, as well as videos, PDFs and other binary formats, are already compressed; using gzip on them won't provide any additional benefit, and can actually make them larger. To compress images, see Optimize images.

share|improve this answer

No, in fact it could make things worse. From Yahoo's Best Practices for Speeding Up Your Web Site:

Image and PDF files should not be gzipped because they are already compressed. Trying to gzip them not only wastes CPU but can potentially increase file sizes.

share|improve this answer

As ima747 states, optimizing your images will most likely be the best thing to do.

I can recommend the freeware tool RIOT: http://luci.criosweb.ro/riot/

share|improve this answer

Trimage is about as good as it gets for optimizing images (depends on OptiPNG, pngcrush and jpegoptim, if I remember). I often use pngcrush directly as part of deployment, e.g.

$ for i in *.png; do pngcrush -rem allb -brute -reduce $i crushed/$i; done;
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.