Smaller images with single-step compression

I’m reviewing image sizes to improve download times in my photo galleries and I’ve obtained the smallest file sizes by performing a single compression step rather than allowing each tool to perform compression during my image pipeline.

Each tool in my workflow has defaults that work well if there is no subsequent or proceeding compression, but produce sub-optimal results when used in an image pipeline where each tool performs compression. My workflow is:

  1. Load and edit photos in Apple’s Photos.app.
  2. Export from Photos.app. I choose a “JPEG Quality” level at export time.
  3. Stamp copyright and licencing info using ExifTool
  4. Resize images as a part of image gallery creation using Pillow, which generally involves a compression step
  5. Perform final optimisation using imageOptim. I’ve used this tool in the past to reduce jpg sizes with great success and it’s consistently given me the best image compression. Adding this step was the trigger point for this investigation.

I did experiments on my Arches gallery whose photos have a total uncompressed size of 103.6MB. I tried four permutations of compression with the results below, noting that the Pillow step also includes resizing:

  1. Compression by Photos.app, Pillow and imageOptim: Final size 4.6MB
    • Photos.app (medium quality) 103.6MB → 19.1MB
    • Pillow (75% quality) 19.1MB → 5.2MB
    • imageOptim (74% quality) 5.2MB → 4.6MB
  2. Compression by Pillow and imageOptim: Final size 4.6MB
    • Photos.app (maximum quality) 103.6MB → 103.6MB
    • Pillow (75% quality) 103.6MB → 5.2MB
    • imageOptim (74% quality) 5.2MB → 4.6MB
  3. Compression by JPEGmini and imageOptim: Final size 4.3MB
    • Photos.app (maximum quality) 103.6MB → 103.6MB
    • Pillow (100% quality) 103.6MB → 27.8MB
    • JPEGmini (no user-selectable settings) 27.8MB → 7.1MB
    • imageOptim (74% quality) 7.1MB → 4.3MB
  4. Compression by imageOptim only: Final size 4.1MB (best result)
    • Photos.app (maximum quality) 103.6MB → 103.6MB
    • Pillow (100% quality) 103.6MB → 27.8MB
    • imageOptim (74% quality) 27.8MB → 4.1MB

The best result comes from performing a single compression step with the best compression tool.

I expected that the individual compression tools would have complementary compression schemes and chaining them together would give the best compression. I suspect now that imageOptim uses all the types of compression schemes available in the other tools and gets the best result because it can take an image with low entropy i.e. an uncompressed image and introduce all the entropy (compression) in a single step.