8

I have photo gallery code that does image re-sizing and thumbnail creation. I use ImageMagick to do this. I ran a gallery page through Google's Page Speed tool and it revealed that the re-sized images and thumbnails both have about an extra 10KB of data (JPEG files specifically).

What can I add to my scripts to optimize the file size?


ADDITIONAL INFORMATION

I am using the imagick::FILTER_LANCZOS filter with a blur setting of 0.9 when calling the resizeImage() function. JPEGs have a quality setting of 80.

Sonny
  • 8,204
  • 7
  • 63
  • 134
  • What arguments are you giving ImageMagick? – asgerhallas Mar 29 '10 at 18:00
  • Updated my question to address the settings/arguments. My understanding is that Google's Page Speed removes 10KB of information in a lossless way, it doesn't further compress the image. Is there meta-data I can strip out somehow? – Sonny Mar 29 '10 at 18:55

2 Answers2

10

I found this SO question, "Tools for JPEG optimization?", that has some good information, but the solutions are outside of PHP. Using hints from that question's solutions I found that there were two lossless optimizations that could be performed:

  1. Optimization of the Huffman coding tables
  2. Removal of meta-data (EXIF, etc)

Both of can be accomplished with ImageMagick this way:

  1. According to ImageMagick documentation, the optimal Huffman coding tables are computed by default. This step is already taken care of, yay!
  2. Removal of meta-data can be accomplished very simply by using the stripImage() method.

One image I tested was reduced by 12KB. The 600x450 file went from 63.42KB to 51.42KB, and the 140x105 thumbnail went from 17.98KB to 5.98KB.

Community
  • 1
  • 1
Sonny
  • 8,204
  • 7
  • 63
  • 134
3

Run your images through Yahoo's SmushIt service, where the images are converted to a PNG with an exact number of colors. No loss in quality, but a loss in weight :)

Adrian A.
  • 172
  • 1
  • 11
  • 1
    That's a slick tool. It doesn't look like they have it set up as a service unfortunately. – Sonny Mar 30 '10 at 21:33