Optimize Image File Sizes 1

Posted by JD 09/07/2011 at 10:00

If you want smaller image file sizes at the same resolution, but files that still display nice. Check out the ImageMagick tool convert.

The size reductions can easily be 50% to 90% without a noticeable loss in quality.

This script worked nicely

#!/bin/sh
for filename in “$@”; do
convert -quality 20 $filename $filename.opt.png
done

on a test file here – the 1.3MB input file became 208KB output. I can’t tell the difference. I was shocked that “20” quality was so good. Normally, I use 80 for JPG saves. Not anymore! Time to run that script through my entire web image directory!

After running a few image file through, some files had artifacts at any level below 95 and actually increased in size. This was for files that were already pretty small and already in PNG format, thumbnails. Switching from PNG to JPG for these files, even with quality set to 95 resulted in 50% smaller files. Going from an 8KB .PNG to a 4KB .JPG could make your web-app almost 50% quicker. Size matters.

I tried a 10.7MB input file (panorama) and had to bump up the quality to 40 for acceptable output. The output file size became 900KB. Not bad for a 9350×1766 image.

  1. JD 09/10/2011 at 15:32

    I completed the conversion of the images on this website using the convert tool today.

    Not all images were compressible. Here’s what I learned:

    • PNG images created by MS-Visio tended to be as small as possible already.
    • Screenshots created using the ImageMagick tool import needed a quality level of 65 or higher and resulted in about 50% size reduction.
    • Screenshots with lots of white (background) usually were fine at 20 and 85% size reductions were pretty common.
    • Photos reduced the best, even at 30-60 quality settings. Usually over a 90% size reduction.
      • 45 – DSC08953-Mills_Lake_Reflection-sm.jpg
      • 30 – DSC09102-Grasshopper-sm.jpg
      • 60 – DSC08850-Monster_Dandelion-sm.jpg
        See the Fort Collins article for those photos which have been re-compressed. Nice enough for the web, I think.