Thanks for reaching out @mananmushtaq02. Images will only be generated in modern image formats if the output image is lower in file size than the one uploaded.
Is there any setting where compression level can be adujusted?
You can use wp_editor_set_quality to change the modern image format quality. Below is an example:
function filter_img_quality( $quality, $mime_type ) {
if ( 'image/avif' === $mime_type ) {
return 55;
}
return $quality;
}
add_filter( 'wp_editor_set_quality', 'filter_img_quality', 10, 2 );
Hopefully the above is of use. Let me know if you have any questions with the above.
In below code I changed $quality = 86; to $quality = 16; and $quality = 96; aswell. But nothing changed in compression quality when I uploaded an image again.
Is there something else to be done
/**
* Returns the default compression quality setting for the mime type.
*
* @since 5.8.1
*
* @param string $mime_type
* @return int The default quality setting for the mime type.
*/
protected function get_default_quality( $mime_type ) {
switch ( $mime_type ) {
case ‘image/webp’:
$quality = 86;
break;
case ‘image/jpeg’:
default:
$quality = $this->default_quality;
}
Is it possible that the image you’re trying to upload is already very low in file size? Feel free to share a link for me to check with if you wish.