Make WordPress Core

Ticket #59760: 59760.diff

File 59760.diff, 2.0 KB (added by adamsilverstein, 6 months ago)
  • src/wp-includes/class-wp-image-editor-gd.php

    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 { 
    7171                                return ( $image_types & IMG_GIF ) != 0;
    7272                        case 'image/webp':
    7373                                return ( $image_types & IMG_WEBP ) != 0;
     74                        case 'image/avif':
     75                                return ( $image_types & IMG_AVIF ) != 0;
    7476                }
    7577
    7678                return false;
  • src/wp-includes/compat.php

    diff --git src/wp-includes/compat.php src/wp-includes/compat.php
    index 5bfdbc23d6..3c8e911a3d 100644
    if ( ! defined( 'IMAGETYPE_WEBP' ) ) { 
    497497if ( ! defined( 'IMG_WEBP' ) ) {
    498498        define( 'IMG_WEBP', IMAGETYPE_WEBP );
    499499}
     500
     501// IMAGETYPE_AVIF constant is only defined in PHP 8.x or later.
     502if ( ! defined( 'IMAGETYPE_AVIF' ) ) {
     503        define( 'IMAGETYPE_AVIF', 19 );
     504}
     505
     506// IMG_AVIF constant is only defined in PHP 8.x or later.
     507if ( ! defined( 'IMG_AVIF' ) ) {
     508        define( 'IMG_AVIF', IMAGETYPE_AVIF );
     509}
  • tests/phpunit/tests/image/editorGd.php

    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 { 
    5151                $this->assertSame( $expected, $gd_image_editor->supports_mime_type( 'image/gif' ) );
    5252        }
    5353
     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
    5466        /**
    5567         * Tests resizing an image, not using crop.
    5668         *