How to stop WordPress from compressing your uploaded jpeg images

Prevent WordPress to compress your jpg images

It seems that WordPress Media Library is compressing uploaded jpeg images by default to 90% of their original quality.
While this is done in order to save your hosting bandwidth sometimes it doesn't work that good especially if your website is oriented to selling or re-selling images(for ex. a designer website or a photography website).

Fortunately there are 3 workarounds for bypassing this "feature".

Use png images instead

This is the fastest and in my opinion best workaround because it doesn't require any messing with WP files and its also the best file format for using images on the web.

PNG format is a lossless compression file format, which makes it a common choice for use on the Web. PNG is a good choice for storing line drawings, text, and iconic graphics at a small file size.

Add a bit of code on your theme's function.php

Another option is to edit your theme's function.php file and add the following two lines, then save and enjoy the difference.

add_filter('jpeg_quality', function($arg){return 100;});
add_filter( 'wp_editor_set_quality', function($arg){return 100;} );

Install a plugin that control the compression level of all jpeg files uploaded

As -almost- always a plugin comes to the rescue, if you don't want to use the png format and you hate messing with your WP files then the WP Resized Image Quality will do the work for you.
You only have to set the compression rate for both jpeg images and their thumbnails and you're done!

Makis Mourelatos

WordPress Security Engineer at FixMyWP
WC Athens 2016 co-organizer, WP Support and Security Aficionado, Wannabe Kitesurfer.

Comments (4)

  1. Quintin Reply

    April 21, 2015 at 6:12 pm

    Hi, I added the code you mentioned:
    add_filter(‘jpeg_quality’, function($arg){return 100;});
    add_filter( ‘wp_editor_set_quality’, function($arg){return 100;} );

    and when i added a new image it was still smaller than the image on my harddrive.
    I downloaded it again just to make sure and the sizes were as follows:
    Original: 192k
    Uploaded file: 95k
    How could this have happened?

    I am really confused about this now.

    1. Fix My WP Reply

      April 26, 2015 at 12:19 am

      Quintin I don’t know what happened, since this guide was written about 2 yrs its not so current. You may also want to see if you have any image compression plugin like wp smush or if your theme is compressing the images.

  2. Yasmin Reply

    January 29, 2017 at 2:08 pm

    Hi, thank you for this post. I’ve had a rubbish time trying to get my blog images to look crisp and vivid on wordpress, and failed with so many pieces of code and plugins. I never even considered using PNG file format, because almost all of my images are photos, but I gave it a go and the latest one I uploaded as my featured image looks lovely. Thank you! As loading time doesn’t bother me too much, this is perfect, even if it takes 1 or 2 seconds longer for readers.

    Could you tell me, are there any other real downsides to using the PNG file format? I’m curious to know before I make all of my images PNG from here on out.

    Thanks again 🙂

    Yas

    1. Fix My WP Reply

      February 6, 2017 at 12:53 am

      Hi Yasmin.
      THe PNG format is usually preferred for showing drawings, shapes and text while JPEG is better at showing photos.

Leave a Reply

Your email address will not be published. Required fields are marked *