Sangat Pedas

WordPress Image (JPG) Compression & Quality

| 0 comments

One of the things I regularly do is see where I can make my sites smaller with less requests and lower file sizes. One of the things I’ve noticed on my WordPress sites and those of others is that images are stored in an extreme high quality and thus with very little compression resulting in larger image file sizes and longer loading times.

The reason for this is that WordPress basically by default uses an image quality of 90 (out of 100) when creating it’s different files sizes ie thumbnails. This even when your original has a quality of let’s say 40. This results in images of the same quality as the original but stored as if the quality is 90 instead of 40. For me a quality of 40 is the best balance between file size and quality, especially because I’m operating in a country where connection speeds are on average still low.

The solution is simple and just takes 2 or 3 simple steps:

1. Add the following code to your theme’s function.php:

 2. Regenerate thumbnails

This can be done with a plugin like “Regenerate Thumbnails” or “Force Regenerate Thumbnails“. The difference between the two is that the latter is exactly the same as the first but will first delete all variants of a certain image first before creating the thumbs and extra configured file sizes. Great to get rid of “ghost” images but make sure that all files sizes used in your posts/blog are still defined.

3. Purge your CDN

If you’re using a CDN like MaxCDN or Cloudfront you need to purge all files. For MaxCDN this is one click in your zone configuration, the only way I could find for Cloudfront is first disabling the Distribution and once the status is “deployed” again enabling the distribution.

Once you’ve done this all your all thumbs as well as newly added will be around 60% smaller in file size. Be aware that this setting only affects jpg files and has no effect on png or gif files!

UPDATE

I’ve been playing around with this and I have to say that the quality of the image compression in WordPress still sucks, big time! I mean it’s all fine for smaller illustrative thumbs but when posting your beloved pictures it will look pretty disappointing. For some sites I take the trade-off, for Sangat Pedas I put the image quality on 100.