Images: enable WebP support.

Add support for uploading, editing and saving WebP images when supported by the server.

Add 'image/webp' to supported mime types. Correctly identify WebP images and sizes even when PHP doesn't support WebP. Resize uploaded WebP files (when supported) and use for front end markup.

Props markoheijne, blobfolio, Clorith, joemcgill, atjn, desrosj, spacedmonkey, marylauc, mikeschroder, hellofromtonya, flixos90.
Fixes #35725.



git-svn-id: https://develop.svn.wordpress.org/trunk@50810 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Adam Silverstein
2021-05-04 14:43:36 +00:00
parent 80302b7b35
commit 6a5ff5aa03
24 changed files with 509 additions and 20 deletions
+26 -1
View File
@@ -59,6 +59,10 @@ class Tests_Image_Functions extends WP_UnitTestCase {
'test-image.psd',
'test-image-zip.tiff',
'test-image.jpg',
'webp-animated.webp',
'webp-lossless.webp',
'webp-lossy.webp',
'webp-transparent.webp',
);
// IMAGETYPE_ICO is only defined in PHP 5.3+.
@@ -92,6 +96,21 @@ class Tests_Image_Functions extends WP_UnitTestCase {
'test-image.jpg',
);
// Add WebP images if the image editor supports them.
$file = DIR_TESTDATA . '/images/test-image.webp';
$editor = wp_get_image_editor( $file );
if ( ( ! is_wp_error( $editor ) ) && $editor->supports_mime_type( 'image/webp' ) ) {
$files = array_merge(
$files,
array(
'webp-animated.webp',
'webp-lossless.webp',
'webp-lossy.webp',
'webp-transparent.webp',
)
);
}
// IMAGETYPE_ICO is only defined in PHP 5.3+.
if ( defined( 'IMAGETYPE_ICO' ) ) {
$files[] = 'test-image.ico';
@@ -174,6 +193,11 @@ class Tests_Image_Functions extends WP_UnitTestCase {
'image/png',
);
// Include WebP in tests when platform supports it.
if ( function_exists( 'imagewebp' ) ) {
array_push( $mime_types, 'image/webp' );
}
// Test each image editor engine.
foreach ( $classes as $class ) {
$img = new $class( DIR_TESTDATA . '/images/canola.jpg' );
@@ -270,7 +294,8 @@ class Tests_Image_Functions extends WP_UnitTestCase {
'jpe' => 'image/jpeg',
'gif' => 'image/gif',
'png' => 'image/png',
'unk' => 'image/jpeg', // Default, unknown.
'webp' => 'image/webp',
'unk' => 'image/jpeg', // Default, unknown.
);
// Test each image editor engine.