Raising image quality in WordPress

You may noticed that when you upload a jpeg image on your WordPress website, it’s size and quality decreases automatically. The purpose of the word jpeg is all this formats: jpg, .jpeg, .jpe, .jif, .jfif, .jfi. ofcourse some times decreasing the size and quality of the image is not very significant but in some images can cause picxelizing which leads to lose image quality totally. The story is that when ever you upload an image with one of these formats in your website, WordPress decrease it’s size and quality to 90 percent of the the primary one without caring to the size and quality of it. (Certainly it is significant and annoying in images saved with JPEG Quality lower than 60.) here in the first step we want to do something to prevent this compressing and then we will see how to make WordPress compressing more than 90 percent on images. ( this one is used when you want to upload a high quality image and you want to save bandwidth and disk space.)

How to prevent compressing images and improving quality of images in WordPress

To prevent compressing images and decreasing the quality of them, we need to use jpeg_quality filter.to do so just put the code …. in the file ” functions.php ” or your site-specific plug-in :

1
2
3
4
add_filter( ‘jpeg_quality’, ‘custom_jpeg_quality’ );
function custom_jpeg_quality( $quality ) {
   return 100;
}

As you see in this code we put 100 for image quality so that no compression and size decreas will hapen.

 

More compression and size decrease of images in WordPress

You may prefer to decrease size and quality of your images for saving bandwidth and disk space. It’s OK. And it is possible. Just use the code …. instead of the previous one.

1
2
3
4
add_filter( ‘jpeg_quality’, ‘custom_jpeg_quality’ );
function custom_jpeg_quality( $quality ) {
   return 65;
}

The only difference between these two codes is the quality defined for jpeg_quality filter. As you see in line 3 in the code the image quality is 65. Changing this number helps you to get your intended result. But i don’t recommend using qualities lower than 65 because these low qualities generally leads to pixelized images and affect your website’s beauty.

Be careful that this filter doesn’t work on images on your website you have uploaded before and your intended changes would be applied to images you will upload from now. So to apply such settings on previous images, you need to use the plug-in “Regenerate Thumbnails” to apply changes on previous images and recreate them with new filter.

Leave a Reply