Make WordPress Core


Ignore:
Timestamp:
02/02/2024 05:46:50 PM (2 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/resize.php

    r54226 r57524  
    8989    }
    9090
     91    /**
     92     * Test resizing AVIF image.
     93     *
     94     * @ticket 51228
     95     */
     96    public function test_resize_avif() {
     97        $file   = DIR_TESTDATA . '/images/avif-lossy.avif';
     98        $editor = wp_get_image_editor( $file );
     99
     100        // Check if the editor supports the avif mime type.
     101        if ( is_wp_error( $editor ) || ! $editor->supports_mime_type( 'image/avif' ) ) {
     102            $this->markTestSkipped( sprintf( 'No AVIF support in the editor engine %s on this system.', $this->editor_engine ) );
     103        }
     104
     105        $image = $this->resize_helper( $file, 25, 25 );
     106
     107        list( $w, $h, $type ) = wp_getimagesize( $image );
     108
     109        unlink( $image );
     110
     111        $this->assertSame( 'avif-lossy-25x25.avif', wp_basename( $image ) );
     112        $this->assertSame( 25, $w );
     113        $this->assertSame( 25, $h );
     114        $this->assertSame( IMAGETYPE_AVIF, $type );
     115    }
     116
    91117    public function test_resize_larger() {
    92118        // image_resize() should refuse to make an image larger.
Note: See TracChangeset for help on using the changeset viewer.