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/src/wp-admin/includes/image.php

    r50552 r50810  
    517517                case 'image/png':
    518518                    $ext = '.png';
     519                    break;
     520                case 'image/webp':
     521                    $ext = '.webp';
    519522                    break;
    520523            }
     
    914917 */
    915918function file_is_displayable_image( $path ) {
    916     $displayable_image_types = array( IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_BMP, IMAGETYPE_ICO );
     919    $displayable_image_types = array( IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_BMP, IMAGETYPE_ICO, IMAGETYPE_WEBP ); // phpcs:ignore PHPCompatibility.Constants.NewConstants.imagetype_webpFound
    917920
    918921    $info = wp_getimagesize( $path );
     
    963966        case 'image/gif':
    964967            $image = imagecreatefromgif( $filepath );
     968            break;
     969        case 'image/webp':
     970            $image = false;
     971            if ( function_exists( 'imagecreatefromwebp' ) ) {
     972                $image = imagecreatefromwebp( $filepath );
     973            }
    965974            break;
    966975        default:
Note: See TracChangeset for help on using the changeset viewer.