admin管理员组文章数量:1202361
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
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
Share Improve this question asked Feb 23, 2020 at 9:44 ClawDudaClawDuda 1411 silver badge4 bronze badges3 Answers
Reset to default 1If 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.
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.
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.
本文标签: imagesShould I not compress my jpeg files before uploading to avoid double compression
版权声明:本文标题:images - Should I not compress my jpeg files before uploading to avoid double compression? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738569656a2100517.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论