How to Disable Image Compression in WordPress

Have you ever wondered why uploaded an image looks pixelated on the front-end even on a fresh WordPress install? Here’s how you can Disable Image Compression in WordPress or change it.
By default, WordPress compresses your images for better performance when you upload them to the media library. It reduces image quality to 82% on upload when processing since version 4.5. If you are a photographer who wants to showcase high quality images on your website, then you can turn off image compression in WordPress.

How to Disable Image Compression in WordPress
How to Disable Image Compression in WordPress

The two most common image formats used on online are JPEG and PNG. Did you know that PNG works better with limited color images such as icon graphics and line drawings but JPEG is smaller file size and high quality for photos and images with lots of colors. So you may think that is handling images in WordPress can be a challenge but it’s simply choosing the right format is JPEG for photos, PNG for graphics.

Fortunately there are some workarounds for bypassing this “feature”.

Use lossless compression file format

RAW, BMP, GIF, and PNG are lossless image formats. WordPress doesn’t reduce the quality of the image if you upload them but your webpage will loading slower, bigger then lose your rank on Google Search Results. WordPress will not modify any image that are lossless formats. You must optimize them by yoursefl before upload into a post or leave them to other 3rd services like: WP Smush, Imagify,…

Disable Image Compression in WordPress

Compressed images will decrease time to load a webpage. Smaller yet high quality images means significantly faster page loading times and frees up server space and bandwidth for more customers. If your website relies heavily on images, reduce image file size is a quick fix to speed up your website. That alone makes WordPress website image optimization worth the effort.

Why do you need to stop WordPress from Compress JPEG images?

Lossless images like PNG is not perfect solution for all posts, so we still use mixed between many image formats. Even you have optimized your JPEG images, the uploaded files changed because the WordPress’ optimal algorithm far different with yours. That’s why you (and I) want to stop WordPress from Compress JPEG uploaded images.

To stop WordPress automatically compressing image, you can override that feature with one line of code without a plugin it tell WordPress upload these files at 100% quality.

Disable Image Compression in WordPress is very easy. You can add a snippet to your theme’s functions.php file:

  • The snippet:
    add_filter('jpeg_quality', function($arg){return 100;});
    add_filter('wp_editor_set_quality', function($arg){return 100;});

    This snippet will completely disable JPEG compression on your site. 100 means no compression (or as near no compression as makes no meaningful difference). The smaller the number, the more compression will be applied.

  • If you change the last number in that line of code, you will be changing the quality of newly uploaded images.
  • Plugins: As -almost- always a plugin comes to the rescue, you can find them via WordPress Repository. Example: Disable JPEG Compression, SMNTCS Deactivate image compression, Image Quality… You only have to set the compression rate for both jpeg images and their thumbnails and you’re done!

Please note this change will not affect images you have already uploaded. So WordPress’s JPG compression setting only applies to those derivative thumbnail versions that are created when you upload images to the media library.

The predetermined image sizes that WordPress uses are:

  • Thumbnail size (150px square)
  • Medium size (maximum 300px width and height)
  • Large size (maximum 1024px width and height)
  • Full size (full/original image size you uploaded)

To change the size and quality of the images you already have in the library, you can either use Regenerate Thumbnails. There are also others. Or if you are familiar with WP-CLI, then you can use this command to regenerate:

$ wp media regenerate

Of course, there are dozens of WordPress plugins that can help you optimize images on your site. I will writing a small review about best WordPress plugins for optimizing images later.

We hope this article has helped you to learn how to get around the new WordPress image compression settings. Do you prefer optimized images or full quality images? Let us know what you think in the comments below.