0

Wordpress compresses jpeg files to a lvl 82 quality. Should I upload my files in 100 quality to avoid double compression? Or will Wordpress know the file is already compressed and will skip this process?

I usually save my files in photoshop in 80 quality , as progressive.

Thank you

3 Answers 3

1

If you want to showcase high-quality images on your website, then you can turn off image compression in WordPress.

You can do that by adding this part of code in your functions.php :

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

Or you can create your plugin :

 <?php 
    /**
    * Plugin Name: Remove WordPress Image Compression
    * Plugin URI: [Plugun URI}
    * Version: 1.0
    * Author: [Your name]
    * Author URI: [Your URI]
    * Description: This will remove the compression WordPress, applies to images when uploading to your media library.
    */
    /**
    * Override the default image quality when resizing and cropping images
    */
    add_filter('jpeg_quality', function($arg){return 100;});

The code above sets the value to 100. It means that WordPress compresses the image at its highest quality.

Now, after activating the plugin, any new image uploaded will no longer be subject to WordPress image compression. Keep in mind that was previously uploaded to activating your plugin will need to be re-uploaded to have the compression removed.

2
  • Hi. Thank you for this. I know I can disable compression. But I concern was to avoid compressing an already compressed picture. Lets assume i leave the compression to 82 ( which is what I am ok with ). Will the thumbnails generated from a file that has quality of 82 be the same as the ones from a file that has 100 ? Or will the ones generated from the 82 file be lower in quality because wordpress will compress it again ? In contrast, for example shopify has a rule.... if the uploaded file has a quality below 85 it will not compress it, but if it's 86 or higher, it will compress it.
    – ClawDuda
    Feb 23, 2020 at 11:07
  • Hi! Basically, I don't know why WordPress doesn't have the same rule as Spotify. Maybe it would be better to see if there is a ticket for this topic in WordPress Core.
    – vbaimas
    Feb 24, 2020 at 10:25
1

From looking at WordPress' sourcecode it appears to use the PHP function imagejpeg to save images. The PHP documentation doesn't mention anything about checking the quality before saving the image.

So I did a test using the identify tool in ImageMagick and uploading images to WordPress.

Image 1: 96% quality before upload & 82% after upload (as expected)

Image 2: 50% quality before upload & 50% after upload.

This admittedly naive test implies (to me at least) that image 2 was left untouched. If it had reduced the quality I'd expect something like 40% quality.

0

Re-compressing a JPEG using the exact same settings does not result in quality loss beyond the initial compression. However, if the settings used by WordPress differ from those applied by your photo editing software, progressive degradation of the image may occur.

The safest route to mitigate this potential degradation is indeed to upload your images at full quality.

You could set the default quality level to match what you use in your photo editing software via the jpeg_quality filter - however, minor variations in the compression settings can still result in degradation. If you choose to go this route you might verify fidelity by checking a hash of the file output from your editing suite against that of the same image uploaded to WordPress.

More on JPEG compression and degradation can be found over on the Photography Stack.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.