How WordPress changes the compression quality of JPEG image

By default, WordPress will compress the uploaded images to avoid better performance and user experience. For a long time, the default compression quality is 90%. After WordPress 4.5, it is reduced to 82% in order to optimize the loading speed of pictures on the mobile phone. But not all users want that. Recently, a customer said that why the images I uploaded were compressed and blurred. Today, I’d like to share how to change the compression quality of JPEG images by WordPress.

popular science: JPEG here refers to a compression method. Files in this compression format are generally called JPEG. The general extensions of such files include. JPEG,. JFIF,. JPG or. JPE, among which. JPG is the most common on mainstream platforms. From Baidu Encyclopedia

WordPress provides “JPEG”_ Quality hook to allow users to customize parameters. We use this hook to modify the image compression quality. The specific method is to add the following code to the current topic functions.php File:

1
2
3
4
5
6
7
8
9
/**
 * 自定义JPEG图片压缩质量
 * https://www.wpdaxue.com/wp_image_editor-jpeg_quality.html
 */
function wpdx_custom_jpeg_quality() {
    //根据实际需求,修改下面的数字即可
    return 90;}
add_filter( 'jpeg_quality', 'wpdx_custom_jpeg_quality');

/***Custom JPEG image compression quality* https://www.wpdaxue.com/wp_ image_ editor-jpeg_ quality.html*/function wpdx_ custom_ jpeg_ quality() {//According to the actual needs, modify the following numbersreturn 90;}add_ filter( ‘jpeg_ quality’, ‘wpdx_ custom_ jpeg_ quality’);

Just change the number in line 7 of the above code according to the actual needs. For example, if you don’t want the image to be compressed, change it to 100

Maybe some friends want to ask, how to modify the compression quality of PNG image? It seems that WordPress itself doesn’t provide a similar hook for PNG images. Neither has she explored it. If you know, share it with us!

Related Article
How to speed up the picture loading speed of WordPress website

Article directory [hidden]Image optimization and its importanceHow to set performance benchmarkSuggestions on speeding up the loading speed of website pictures1. Read more

How to get the number of articles and comments of the current logined user in WordPress

When developing WordPress Theme user center, I want to get the number of articles and comments of current logged in Read more

WordPress tips: get statistics of the number of pictures in the article

As far as I know, WordPress has no function to count the number of pictures in the article, so to Read more

WordPress details optimization to automatically add ALT and title information to the article image

Friends who know a little bit about SEO optimization should understand that image ALT and image title optimization are very Read more

Leave a Reply

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

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-spam image