mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
Media: enable AVIF support.
Add support for uploading, editing and saving AVIF images when supported by the server. Add 'image/avif' to supported mime types. Correctly identify AVIF images and sizes even when PHP doesn't support AVIF. Resize uploaded AVIF files (when supported) and use for front end markup. Props adamsilverstein, lukefiretoss, ayeshrajans, navjotjsingh, Tyrannous, jb510, gregbenz, nickpagz, JavierCasares, mukesh27, yguyon, swissspidy. Fixes #51228. git-svn-id: https://develop.svn.wordpress.org/trunk@57524 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
0
tests/phpunit/data/images/avif-animated.avif
Normal file
0
tests/phpunit/data/images/avif-animated.avif
Normal file
0
tests/phpunit/data/images/avif-lossless.avif
Normal file
0
tests/phpunit/data/images/avif-lossless.avif
Normal file
0
tests/phpunit/data/images/avif-lossy.avif
Normal file
0
tests/phpunit/data/images/avif-lossy.avif
Normal file
0
tests/phpunit/data/images/avif-transparent.avif
Normal file
0
tests/phpunit/data/images/avif-transparent.avif
Normal file
0
tests/phpunit/data/images/colors_hdr_p3.avif
Normal file
0
tests/phpunit/data/images/colors_hdr_p3.avif
Normal file
@@ -1370,6 +1370,26 @@ class Tests_Functions extends WP_UnitTestCase {
|
||||
DIR_TESTDATA . '/uploads/dashicons.woff',
|
||||
false,
|
||||
),
|
||||
// Animated AVIF.
|
||||
array(
|
||||
DIR_TESTDATA . '/images/avif-animated.avif',
|
||||
'image/avif',
|
||||
),
|
||||
// Lossless AVIF.
|
||||
array(
|
||||
DIR_TESTDATA . '/images/avif-lossless.avif',
|
||||
'image/avif',
|
||||
),
|
||||
// Lossy AVIF.
|
||||
array(
|
||||
DIR_TESTDATA . '/images/avif-lossy.avif',
|
||||
'image/avif',
|
||||
),
|
||||
// Transparent AVIF.
|
||||
array(
|
||||
DIR_TESTDATA . '/images/avif-transparent.avif',
|
||||
'image/avif',
|
||||
),
|
||||
);
|
||||
|
||||
return $data;
|
||||
@@ -1496,6 +1516,50 @@ class Tests_Functions extends WP_UnitTestCase {
|
||||
DIR_TESTDATA . '/uploads/dashicons.woff',
|
||||
false,
|
||||
),
|
||||
// Animated AVIF.
|
||||
array(
|
||||
DIR_TESTDATA . '/images/avif-animated.avif',
|
||||
array(
|
||||
150,
|
||||
150,
|
||||
IMAGETYPE_AVIF,
|
||||
'width="150" height="150"',
|
||||
'mime' => 'image/avif',
|
||||
),
|
||||
),
|
||||
// Lossless AVIF.
|
||||
array(
|
||||
DIR_TESTDATA . '/images/avif-lossless.avif',
|
||||
array(
|
||||
400,
|
||||
400,
|
||||
IMAGETYPE_AVIF,
|
||||
'width="400" height="400"',
|
||||
'mime' => 'image/avif',
|
||||
),
|
||||
),
|
||||
// Lossy AVIF.
|
||||
array(
|
||||
DIR_TESTDATA . '/images/avif-lossy.avif',
|
||||
array(
|
||||
400,
|
||||
400,
|
||||
IMAGETYPE_AVIF,
|
||||
'width="400" height="400"',
|
||||
'mime' => 'image/avif',
|
||||
),
|
||||
),
|
||||
// Transparent AVIF.
|
||||
array(
|
||||
DIR_TESTDATA . '/images/avif-transparent.avif',
|
||||
array(
|
||||
128,
|
||||
128,
|
||||
IMAGETYPE_AVIF,
|
||||
'width="128" height="128"',
|
||||
'mime' => 'image/avif',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return $data;
|
||||
|
||||
@@ -292,12 +292,6 @@ class Tests_Image_Editor extends WP_Image_UnitTestCase {
|
||||
*
|
||||
*/
|
||||
public function test_wp_get_webp_info( $file, $expected ) {
|
||||
$editor = wp_get_image_editor( $file );
|
||||
|
||||
if ( is_wp_error( $editor ) || ! $editor->supports_mime_type( 'image/webp' ) ) {
|
||||
$this->markTestSkipped( sprintf( 'No WebP support in the editor engine %s on this system.', $this->editor_engine ) );
|
||||
}
|
||||
|
||||
$file_data = wp_get_webp_info( $file );
|
||||
$this->assertSame( $expected, $file_data );
|
||||
}
|
||||
@@ -363,4 +357,105 @@ class Tests_Image_Editor extends WP_Image_UnitTestCase {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test wp_get_avif_info.
|
||||
*
|
||||
* @ticket 51228
|
||||
*
|
||||
* @dataProvider data_wp_get_avif_info
|
||||
*
|
||||
* @param string $file The path to the AVIF file for testing.
|
||||
* @param array $expected The expected AVIF file information.
|
||||
*/
|
||||
public function test_wp_get_avif_info( $file, $expected ) {
|
||||
$file_data = wp_get_avif_info( $file );
|
||||
$this->assertSame( $expected, $file_data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for test_wp_get_avif_info().
|
||||
*/
|
||||
public function data_wp_get_avif_info() {
|
||||
return array(
|
||||
// Standard JPEG.
|
||||
array(
|
||||
DIR_TESTDATA . '/images/test-image.jpg',
|
||||
array(
|
||||
'width' => false,
|
||||
'height' => false,
|
||||
'bit_depth' => false,
|
||||
'num_channels' => false,
|
||||
),
|
||||
),
|
||||
// Standard GIF.
|
||||
array(
|
||||
DIR_TESTDATA . '/images/test-image.gif',
|
||||
array(
|
||||
'width' => false,
|
||||
'height' => false,
|
||||
'bit_depth' => false,
|
||||
'num_channels' => false,
|
||||
),
|
||||
),
|
||||
// Animated AVIF.
|
||||
array(
|
||||
DIR_TESTDATA . '/images/avif-animated.avif',
|
||||
array(
|
||||
'width' => 150,
|
||||
'height' => 150,
|
||||
'bit_depth' => 8,
|
||||
'num_channels' => 4,
|
||||
),
|
||||
),
|
||||
// Lossless AVIF.
|
||||
array(
|
||||
DIR_TESTDATA . '/images/avif-lossless.avif',
|
||||
array(
|
||||
'width' => 400,
|
||||
'height' => 400,
|
||||
'bit_depth' => 8,
|
||||
'num_channels' => 3,
|
||||
),
|
||||
),
|
||||
// Lossy AVIF.
|
||||
array(
|
||||
DIR_TESTDATA . '/images/avif-lossy.avif',
|
||||
array(
|
||||
'width' => 400,
|
||||
'height' => 400,
|
||||
'bit_depth' => 8,
|
||||
'num_channels' => 3,
|
||||
),
|
||||
),
|
||||
// Transparent AVIF.
|
||||
array(
|
||||
DIR_TESTDATA . '/images/avif-transparent.avif',
|
||||
array(
|
||||
'width' => 128,
|
||||
'height' => 128,
|
||||
'bit_depth' => 12,
|
||||
'num_channels' => 4,
|
||||
),
|
||||
),
|
||||
array(
|
||||
DIR_TESTDATA . '/images/color_grid_alpha_nogrid.avif',
|
||||
array(
|
||||
'width' => 80,
|
||||
'height' => 80,
|
||||
'bit_depth' => 8,
|
||||
'num_channels' => 4,
|
||||
),
|
||||
),
|
||||
array(
|
||||
DIR_TESTDATA . '/images/colors_hdr_p3.avif',
|
||||
array(
|
||||
'width' => 200,
|
||||
'height' => 200,
|
||||
'bit_depth' => 10,
|
||||
'num_channels' => 3,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,6 +111,10 @@ class Tests_Image_Functions extends WP_UnitTestCase {
|
||||
'webp-lossless.webp',
|
||||
'webp-lossy.webp',
|
||||
'webp-transparent.webp',
|
||||
'avif-animated.avif',
|
||||
'avif-lossless.avif',
|
||||
'avif-lossy.avif',
|
||||
'avif-transparent.avif',
|
||||
);
|
||||
|
||||
return $this->text_array_to_dataprovider( $files );
|
||||
@@ -186,6 +190,17 @@ class Tests_Image_Functions extends WP_UnitTestCase {
|
||||
$files[] = 'webp-transparent.webp';
|
||||
}
|
||||
|
||||
// Add AVIF images if the image editor supports them.
|
||||
$file = DIR_TESTDATA . '/images/avif-lossless.avif';
|
||||
$editor = wp_get_image_editor( $file );
|
||||
|
||||
if ( ! is_wp_error( $editor ) && $editor->supports_mime_type( 'image/avif' ) ) {
|
||||
$files[] = 'avif-animated.avif';
|
||||
$files[] = 'avif-lossless.avif';
|
||||
$files[] = 'avif-lossy.avif';
|
||||
$files[] = 'avif-transparent.avif';
|
||||
}
|
||||
|
||||
return $this->text_array_to_dataprovider( $files );
|
||||
}
|
||||
|
||||
|
||||
@@ -88,6 +88,32 @@ abstract class WP_Tests_Image_Resize_UnitTestCase extends WP_Image_UnitTestCase
|
||||
$this->assertSame( IMAGETYPE_WEBP, $type );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test resizing AVIF image.
|
||||
*
|
||||
* @ticket 51228
|
||||
*/
|
||||
public function test_resize_avif() {
|
||||
$file = DIR_TESTDATA . '/images/avif-lossy.avif';
|
||||
$editor = wp_get_image_editor( $file );
|
||||
|
||||
// Check if the editor supports the avif mime type.
|
||||
if ( is_wp_error( $editor ) || ! $editor->supports_mime_type( 'image/avif' ) ) {
|
||||
$this->markTestSkipped( sprintf( 'No AVIF support in the editor engine %s on this system.', $this->editor_engine ) );
|
||||
}
|
||||
|
||||
$image = $this->resize_helper( $file, 25, 25 );
|
||||
|
||||
list( $w, $h, $type ) = wp_getimagesize( $image );
|
||||
|
||||
unlink( $image );
|
||||
|
||||
$this->assertSame( 'avif-lossy-25x25.avif', wp_basename( $image ) );
|
||||
$this->assertSame( 25, $w );
|
||||
$this->assertSame( 25, $h );
|
||||
$this->assertSame( IMAGETYPE_AVIF, $type );
|
||||
}
|
||||
|
||||
public function test_resize_larger() {
|
||||
// image_resize() should refuse to make an image larger.
|
||||
$image = $this->resize_helper( DIR_TESTDATA . '/images/test-image.jpg', 100, 100 );
|
||||
|
||||
Reference in New Issue
Block a user