Make WordPress Core


Ignore:
Timestamp:
02/02/2024 05:46:50 PM (3 years ago)
Author:
adamsilverstein
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/image/editor.php

    r56547 r57524  
    293293         */
    294294        public function test_wp_get_webp_info( $file, $expected ) {
    295                 $editor = wp_get_image_editor( $file );
    296 
    297                 if ( is_wp_error( $editor ) || ! $editor->supports_mime_type( 'image/webp' ) ) {
    298                         $this->markTestSkipped( sprintf( 'No WebP support in the editor engine %s on this system.', $this->editor_engine ) );
    299                 }
    300 
    301295                $file_data = wp_get_webp_info( $file );
    302296                $this->assertSame( $expected, $file_data );
    … …  
    364358                );
    365359        }
     360
     361        /**
     362         * Test wp_get_avif_info.
     363         *
     364         * @ticket 51228
     365         *
     366         * @dataProvider data_wp_get_avif_info
     367         *
     368         * @param string $file     The path to the AVIF file for testing.
     369         * @param array  $expected The expected AVIF file information.
     370         */
     371        public function test_wp_get_avif_info( $file, $expected ) {
     372                $file_data = wp_get_avif_info( $file );
     373                $this->assertSame( $expected, $file_data );
     374        }
     375
     376        /**
     377         * Data provider for test_wp_get_avif_info().
     378         */
     379        public function data_wp_get_avif_info() {
     380                return array(
     381                        // Standard JPEG.
     382                        array(
     383                                DIR_TESTDATA . '/images/test-image.jpg',
     384                                array(
     385                                        'width'        => false,
     386                                        'height'       => false,
     387                                        'bit_depth'    => false,
     388                                        'num_channels' => false,
     389                                ),
     390                        ),
     391                        // Standard GIF.
     392                        array(
     393                                DIR_TESTDATA . '/images/test-image.gif',
     394                                array(
     395                                        'width'        => false,
     396                                        'height'       => false,
     397                                        'bit_depth'    => false,
     398                                        'num_channels' => false,
     399                                ),
     400                        ),
     401                        // Animated AVIF.
     402                        array(
     403                                DIR_TESTDATA . '/images/avif-animated.avif',
     404                                array(
     405                                        'width'        => 150,
     406                                        'height'       => 150,
     407                                        'bit_depth'    => 8,
     408                                        'num_channels' => 4,
     409                                ),
     410                        ),
     411                        // Lossless AVIF.
     412                        array(
     413                                DIR_TESTDATA . '/images/avif-lossless.avif',
     414                                array(
     415                                        'width'        => 400,
     416                                        'height'       => 400,
     417                                        'bit_depth'    => 8,
     418                                        'num_channels' => 3,
     419                                ),
     420                        ),
     421                        // Lossy AVIF.
     422                        array(
     423                                DIR_TESTDATA . '/images/avif-lossy.avif',
     424                                array(
     425                                        'width'        => 400,
     426                                        'height'       => 400,
     427                                        'bit_depth'    => 8,
     428                                        'num_channels' => 3,
     429                                ),
     430                        ),
     431                        // Transparent AVIF.
     432                        array(
     433                                DIR_TESTDATA . '/images/avif-transparent.avif',
     434                                array(
     435                                        'width'        => 128,
     436                                        'height'       => 128,
     437                                        'bit_depth'    => 12,
     438                                        'num_channels' => 4,
     439                                ),
     440                        ),
     441                        array(
     442                                DIR_TESTDATA . '/images/color_grid_alpha_nogrid.avif',
     443                                array(
     444                                        'width'        => 80,
     445                                        'height'       => 80,
     446                                        'bit_depth'    => 8,
     447                                        'num_channels' => 4,
     448                                ),
     449                        ),
     450                        array(
     451                                DIR_TESTDATA . '/images/colors_hdr_p3.avif',
     452                                array(
     453                                        'width'        => 200,
     454                                        'height'       => 200,
     455                                        'bit_depth'    => 10,
     456                                        'num_channels' => 3,
     457                                ),
     458                        ),
     459                );
     460        }
    366461}
Note: See TracChangeset for help on using the changeset viewer.