mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-16 23:00:21 +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:
@@ -1225,6 +1225,29 @@ class Tests_Functions extends WP_UnitTestCase {
|
||||
$this->assertSame( $expected, wp_get_image_mime( $file ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 35725
|
||||
* @dataProvider data_wp_getimagesize
|
||||
*/
|
||||
public function test_wp_getimagesize( $file, $expected ) {
|
||||
if ( ! is_callable( 'exif_imagetype' ) && ! function_exists( 'getimagesize' ) ) {
|
||||
$this->markTestSkipped( 'The exif PHP extension is not loaded.' );
|
||||
}
|
||||
|
||||
$result = wp_getimagesize( $file );
|
||||
|
||||
// The getimagesize() function varies in its response, so
|
||||
// let's restrict comparison to expected keys only.
|
||||
if ( is_array( $expected ) ) {
|
||||
foreach ( $expected as $k => $v ) {
|
||||
$this->assertEquals( true, isset( $result[ $k ] ) );
|
||||
$this->assertEquals( $expected[ $k ], $result[ $k ] );
|
||||
}
|
||||
} else {
|
||||
$this->assertEquals( $expected, $result );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 39550
|
||||
* @dataProvider _wp_check_filetype_and_ext_data
|
||||
@@ -1313,6 +1336,129 @@ class Tests_Functions extends WP_UnitTestCase {
|
||||
DIR_TESTDATA . '/images/test-image-mime-jpg.png',
|
||||
'image/jpeg',
|
||||
),
|
||||
// Animated WebP.
|
||||
array(
|
||||
DIR_TESTDATA . '/images/webp-animated.webp',
|
||||
'image/webp',
|
||||
),
|
||||
// Lossless WebP.
|
||||
array(
|
||||
DIR_TESTDATA . '/images/webp-lossless.webp',
|
||||
'image/webp',
|
||||
),
|
||||
// Lossy WebP.
|
||||
array(
|
||||
DIR_TESTDATA . '/images/webp-lossy.webp',
|
||||
'image/webp',
|
||||
),
|
||||
// Transparent WebP.
|
||||
array(
|
||||
DIR_TESTDATA . '/images/webp-transparent.webp',
|
||||
'image/webp',
|
||||
),
|
||||
// Not an image.
|
||||
array(
|
||||
DIR_TESTDATA . '/uploads/dashicons.woff',
|
||||
false,
|
||||
),
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Data profider for test_wp_getimagesize();
|
||||
*/
|
||||
public function data_wp_getimagesize() {
|
||||
$data = array(
|
||||
// Standard JPEG.
|
||||
array(
|
||||
DIR_TESTDATA . '/images/test-image.jpg',
|
||||
array(
|
||||
50,
|
||||
50,
|
||||
IMAGETYPE_JPEG,
|
||||
'width="50" height="50"',
|
||||
'mime' => 'image/jpeg',
|
||||
),
|
||||
),
|
||||
// Standard GIF.
|
||||
array(
|
||||
DIR_TESTDATA . '/images/test-image.gif',
|
||||
array(
|
||||
50,
|
||||
50,
|
||||
IMAGETYPE_GIF,
|
||||
'width="50" height="50"',
|
||||
'mime' => 'image/gif',
|
||||
),
|
||||
),
|
||||
// Standard PNG.
|
||||
array(
|
||||
DIR_TESTDATA . '/images/test-image.png',
|
||||
array(
|
||||
50,
|
||||
50,
|
||||
IMAGETYPE_PNG,
|
||||
'width="50" height="50"',
|
||||
'mime' => 'image/png',
|
||||
),
|
||||
),
|
||||
// Image with wrong extension.
|
||||
array(
|
||||
DIR_TESTDATA . '/images/test-image-mime-jpg.png',
|
||||
array(
|
||||
50,
|
||||
50,
|
||||
IMAGETYPE_JPEG,
|
||||
'width="50" height="50"',
|
||||
'mime' => 'image/jpeg',
|
||||
),
|
||||
),
|
||||
// Animated WebP.
|
||||
array(
|
||||
DIR_TESTDATA . '/images/webp-animated.webp',
|
||||
array(
|
||||
100,
|
||||
100,
|
||||
IMAGETYPE_WEBP,
|
||||
'width="100" height="100"',
|
||||
'mime' => 'image/webp',
|
||||
),
|
||||
),
|
||||
// Lossless WebP.
|
||||
array(
|
||||
DIR_TESTDATA . '/images/webp-lossless.webp',
|
||||
array(
|
||||
1200,
|
||||
675,
|
||||
IMAGETYPE_WEBP,
|
||||
'width="1200" height="675"',
|
||||
'mime' => 'image/webp',
|
||||
),
|
||||
),
|
||||
// Lossy WebP.
|
||||
array(
|
||||
DIR_TESTDATA . '/images/webp-lossy.webp',
|
||||
array(
|
||||
1200,
|
||||
675,
|
||||
IMAGETYPE_WEBP,
|
||||
'width="1200" height="675"',
|
||||
'mime' => 'image/webp',
|
||||
),
|
||||
),
|
||||
// Transparent WebP.
|
||||
array(
|
||||
DIR_TESTDATA . '/images/webp-transparent.webp',
|
||||
array(
|
||||
1200,
|
||||
675,
|
||||
IMAGETYPE_WEBP,
|
||||
'width="1200" height="675"',
|
||||
'mime' => 'image/webp',
|
||||
),
|
||||
),
|
||||
// Not an image.
|
||||
array(
|
||||
DIR_TESTDATA . '/uploads/dashicons.woff',
|
||||
|
||||
Reference in New Issue
Block a user