mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-10-04 06:37:06 +00:00
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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user