Change the Image Quality in WordPress


Categories
Tags

By default, WordPress compresses images uploaded via the media uploader. Learn how to change the level of compression in your functions file to better suit your website.

WordPress will compress images uploaded to your site by 10%, meaning that the quality of your images will be 90% of their original quality after you upload them. You might not want your images to be compressed at all, or you may want to compress them further. In the examples below we’ll show you how to remove compression entirely or how to adjust the level to something more appropriate to the requirements of your website.

Stop Auto Compression of Images

On a website that makes use of high quality images you may want to keep these at full quality. For a photographer, illustrator or graphic designer for example, image quality may be preferred over saving space and performance. You can achieve this by adding the code below to your functions file. The first filter sets the quality of jpeg’s to 100%. The second filter does the same thing but for all images. The reason we are using both in this example is because the wp_editor_set_quality filter is superseded by the jpeg_quality filter, so by setting both filters we’re hitting all image types:

//stop auto compression of images
add_filter('jpeg_quality', function($arg){return 100;});
add_filter( 'wp_editor_set_quality', function($arg){return 100;} );

Compress your Images Further

On the flip side you might like the idea of compressing your images further, to save space on your hosting platform and improve performance. You might not need your images to be particularly high in quality. In this case you can adjust the levels however you like. In the example below we’ve set the quality of our images to 75%:

//adjust auto compression of images
add_filter('jpeg_quality', function($arg){return 75;});
add_filter( 'wp_editor_set_quality', function($arg){return 75;} );

Regenerate Thumbnails

If you have existing images that were uploaded prior to changing the level of compression then you’ll probably want to regenerate these. You can do this with the Regenerate Thumbnails plugin by Alex Mills.

Comments

We welcome comments! Please read the disclaimer.

Disclaimer and Legal Information

The use of any content found on or via this website (code, how to guides etc.) is done so at your own risk. We take no responsibility for any issues encountered.

This blog and its authors will not be held responsible for any misuse, reuse, recycled and cited/uncited copies of content from this website by others.

The views and opinions expressed in this blog are those of the authors and do not necessarily reflect the position or opinion of any other agency, organisation, employer or company.

Comments are moderated but we do not take any responsibility for any libel or litigation that results from something written in a comment. We reserve the right to reject or delete any comment for any reason whatsoever (abusive, profane, rude etc). Please keep your comments polite and relevant.

We are happy for you to quote and share our content in any reasonable manner, e.g. post links to our blogs on social media, but not in any way that suggests that we, or our authors, endorse you, your use or your views.

We appreciate attributions, e.g. a link to our website (www.dragoncode.co.uk).