diff --git src/wp-includes/class-wp-image-editor-gd.php src/wp-includes/class-wp-image-editor-gd.php
index de079357fb..43eacd3a4c 100644
|
|
class WP_Image_Editor_GD extends WP_Image_Editor { |
71 | 71 | return ( $image_types & IMG_GIF ) != 0; |
72 | 72 | case 'image/webp': |
73 | 73 | return ( $image_types & IMG_WEBP ) != 0; |
| 74 | case 'image/avif': |
| 75 | return ( $image_types & IMG_AVIF ) != 0; |
74 | 76 | } |
75 | 77 | |
76 | 78 | return false; |
diff --git src/wp-includes/compat.php src/wp-includes/compat.php
index 5bfdbc23d6..3c8e911a3d 100644
|
|
if ( ! defined( 'IMAGETYPE_WEBP' ) ) { |
497 | 497 | if ( ! defined( 'IMG_WEBP' ) ) { |
498 | 498 | define( 'IMG_WEBP', IMAGETYPE_WEBP ); |
499 | 499 | } |
| 500 | |
| 501 | // IMAGETYPE_AVIF constant is only defined in PHP 8.x or later. |
| 502 | if ( ! defined( 'IMAGETYPE_AVIF' ) ) { |
| 503 | define( 'IMAGETYPE_AVIF', 19 ); |
| 504 | } |
| 505 | |
| 506 | // IMG_AVIF constant is only defined in PHP 8.x or later. |
| 507 | if ( ! defined( 'IMG_AVIF' ) ) { |
| 508 | define( 'IMG_AVIF', IMAGETYPE_AVIF ); |
| 509 | } |
diff --git tests/phpunit/tests/image/editorGd.php tests/phpunit/tests/image/editorGd.php
index 640561238a..8c52d255f8 100644
|
|
class Tests_Image_Editor_GD extends WP_Image_UnitTestCase { |
51 | 51 | $this->assertSame( $expected, $gd_image_editor->supports_mime_type( 'image/gif' ) ); |
52 | 52 | } |
53 | 53 | |
| 54 | public function test_supports_mime_type_webp() { |
| 55 | $gd_image_editor = new WP_Image_Editor_GD( null ); |
| 56 | $expected = (bool) ( imagetypes() & IMG_WEBP ); |
| 57 | $this->assertSame( $expected, $gd_image_editor->supports_mime_type( 'image/webp' ) ); |
| 58 | } |
| 59 | |
| 60 | public function test_supports_mime_type_avif() { |
| 61 | $gd_image_editor = new WP_Image_Editor_GD( null ); |
| 62 | $expected = (bool) ( imagetypes() & IMG_AVIF ); |
| 63 | $this->assertSame( $expected, $gd_image_editor->supports_mime_type( 'image/avif' ) ); |
| 64 | } |
| 65 | |
54 | 66 | /** |
55 | 67 | * Tests resizing an image, not using crop. |
56 | 68 | * |