May 10 15

Google PageSpeed reported that the JPEG images of a web project I recently worked on should be optimized i.e. compressed. So, I used jpegoptim in batch mode on OS X for the job. You need to build the jpegoptim binary for OS X yourself. Short manual:

  1. Download jpegoptim sources from developer’s website
  2. Unpack the TAR ball
  3. Navigate to the unpacked sources in a shell
  4. chmod a+x configure
  5. ./configure
  6. make install

In my case the libjpeg library was missing. I had to download and build libjpeg as part of the official IJG JPEG 8 code. Once everything was in place I simply ran jpegoptim from the command line for all JPEG files in a folder.

jpegoptim -o --dest=./compressed --strip-all *.jpg

This optimizes all .jpg files in the current folder with maximum compression (–strip-all) and saves the compressed files in the ‘compressed’ sub folder (had to be created first).

One Response to “Batch compressing JPEG images”

  1. Glenn Roberts Says:

    Hi there – thanks for this tip – I’ve also blogged about it here: http://www.glenn-roberts.com/cleanup-your-photo-library-batch-compress-you
    I’ve also added some minor code fixes I put up on GitHub for all to benefit from: http://github.com/glennr/jpegoptim

    I just couldn’t bring myself to go back to CVS after 9 years of hell working with that ‘source code control’ system :-) Git FTW.

    Cheers

Leave a Reply