Make WordPress Core


Ignore:
Timestamp:
05/04/2021 02:43:36 PM (4 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/functions.php

    r49450 r50810  
    6060            'test-image-zip.tiff',
    6161            'test-image.jpg',
     62            'webp-animated.webp',
     63            'webp-lossless.webp',
     64            'webp-lossy.webp',
     65            'webp-transparent.webp',
    6266        );
    6367
     
    9296            'test-image.jpg',
    9397        );
     98
     99        // Add WebP images if the image editor supports them.
     100        $file   = DIR_TESTDATA . '/images/test-image.webp';
     101        $editor = wp_get_image_editor( $file );
     102        if ( ( ! is_wp_error( $editor ) ) && $editor->supports_mime_type( 'image/webp' ) ) {
     103            $files = array_merge(
     104                $files,
     105                array(
     106                    'webp-animated.webp',
     107                    'webp-lossless.webp',
     108                    'webp-lossy.webp',
     109                    'webp-transparent.webp',
     110                )
     111            );
     112        }
    94113
    95114        // IMAGETYPE_ICO is only defined in PHP 5.3+.
     
    175194        );
    176195
     196        // Include WebP in tests when platform supports it.
     197        if ( function_exists( 'imagewebp' ) ) {
     198            array_push( $mime_types, 'image/webp' );
     199        }
     200
    177201        // Test each image editor engine.
    178202        foreach ( $classes as $class ) {
     
    271295            'gif'  => 'image/gif',
    272296            'png'  => 'image/png',
    273             'unk'  => 'image/jpeg', // Default, unknown.
     297            'webp' => 'image/webp',
     298            'unk'  => 'image/jpeg',   // Default, unknown.
    274299        );
    275300
Note: See TracChangeset for help on using the changeset viewer.