Last active
August 25, 2022 19:07
-
-
Save adamsilverstein/262ec44a5cebe7ff8601b1e73301d07f to your computer and use it in GitHub Desktop.
Test setting WebP quality
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Use the `wp_editor_set_quality` filter for testing. | |
*/ | |
function set_webp_quality( $quality, $mime_type ) { | |
error_log( sprintf( 'wp_editor_set_quality mime type: %s', $mime_type ) ); | |
if ( 'image/webp' === $mime_type ) { | |
return 1; | |
} | |
return $quality; | |
} | |
add_filter( 'wp_editor_set_quality', 'set_webp_quality', 10, 2 ); | |
/** | |
* Specify WebP file output. | |
*/ | |
add_filter( 'image_editor_output_format', function() { | |
return array( | |
'image/jpeg' => 'image/webp', | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment