Add $filepath to the filter sgo_webp_quality for granular control

[ad_1]

I’d like to suggest an opportunity in the Code to apply a Filter so we (developers) can fine tune optimization quality based on media type and filename (size).

Use Case. Larger images needs higher compression while smaller images need lower/no compression.

Current Filter
$quality = apply_filters( 'sgo_webp_quality', 80 );

Current Issue: $quality is set to the same irregardless of $type. We need a way to know the $filepath in the filter for this.

Suggested Filter
$quality = apply_filters( 'sgo_webp_quality', 80, $filepath );

Proposed Solution

add_filter( 'sgo_webp_quality', 'my_sgo_webp_quality' );
function my_sgo_webp_quality( $quality, $filepath ){
$type = exif_imagetype( $filepath );
$filesize = filesize( $filepath );

switch($type){
case: IMAGETYPE_JPEG:
if $filesize > 100000 {
$quality= 45;
} else {
$quality= 65;
}
break;
default:
}

return $quality;
}

Thx!

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer