Batch compressing JPEG images

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 thought on “Batch compressing JPEG images

Leave a Reply