Better image compression settings for WordPress

With ever more internet activity taking place over mobile connections, it makes sense to optimize website content as much as possible so that content loads as quickly as possible. One of the best places to make savings is amongst images, as they are the “heaviest” content on a regular website. (Aside from video, of course.)

A complicated algorithm in server-side tools like GD or ImageMagick means that even where images are optimized as much as possible in (for example) Lightroom, compression when uploading to CMS like WordPress can sometimes create images which are actually larger than the originals.

A tip for WordPress developers is to use the jpeg_quality hook to set a lower quality setting than WordPress’ default setting of 90%. Detailed research and testing by Joe McGill in preparation for this proposal to WordPress Core indicates that a value of around 82% produces significant size savings, whilst remaining within acceptable optical similarity limits.

My own brief testing this morning shows that a value of 80% is fine too: by setting this value to apply to JPGs generated on this website, I could reduce the total size of images added to the site in December 2015 from 135mb to 101mb, using the following code in my functions.php and then re-generating the thumbnails using this plugin.