WordPress JPEG Thumbnail Image Quality Setting and Adjustment

By Glyn Mooney:

If you want to set the image quality of the thumbnails from the “the_post_thumbnail” function/template tag add the following line to your functions.php file to override the default value of 90%:

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

On some production environments you may get a “unexpected T_FUNCTION” error (older versions of PHP 5 don’t like anonymous functions). In this situation go for the following:

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

Here I’m setting the quality to 100%, but you can set it to whatever value suits your project. You have to set the “$arg” to swallow the argument that get’s passed to the original function in the “image_resize” function in the media.php file.

Leave a Comment