Make WordPress Core


Ignore:
Timestamp:
05/04/2021 02:43:36 PM (3 years ago)
Author:
adamsilverstein
Message:

Images: enable WebP support.

Add support for uploading, editing and saving WebP images when supported by the server.

Add 'image/webp' to supported mime types. Correctly identify WebP images and sizes even when PHP doesn't support WebP. Resize uploaded WebP files (when supported) and use for front end markup.

Props markoheijne, blobfolio, Clorith, joemcgill, atjn, desrosj, spacedmonkey, marylauc, mikeschroder, hellofromtonya, flixos90.
Fixes #35725.

File:
1 edited

Legend:

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

    r50463 r50810  
    6565    }
    6666
     67    function test_resize_webp() {
     68        $file   = DIR_TESTDATA . '/images/test-image.webp';
     69        $editor = wp_get_image_editor( $file );
     70
     71        // Check if the editor supports the webp mime type.
     72        if ( is_wp_error( $editor ) || ! $editor->supports_mime_type( 'image/webp' ) ) {
     73            $this->markTestSkipped( sprintf( 'Skipping test: no WebP support in the editor engine %s on this system.', $this->editor_engine ) );
     74        } else {
     75            $image = $this->resize_helper( $file, 25, 25 );
     76            $this->assertSame( 'test-image-25x25.webp', wp_basename( $image ) );
     77            list($w, $h, $type) = wp_getimagesize( $image );
     78            $this->assertSame( 25, $w );
     79            $this->assertSame( 25, $h );
     80            $this->assertSame( IMAGETYPE_WEBP, $type );
     81            unlink( $image );
     82        }
     83    }
     84
    6785    function test_resize_larger() {
    6886        // image_resize() should refuse to make an image larger.
Note: See TracChangeset for help on using the changeset viewer.