Add $filepath to the filter sgo_webp_quality for granular control
-
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!
- The topic ‘Add $filepath to the filter sgo_webp_quality for granular control’ is closed to new replies.