Make WordPress Core

Changeset 59413


Ignore:
Timestamp:
11/18/2024 06:03:22 PM (2 months ago)
Author:
desrosj
Message:

Media: Avoid running expensive logic twice using GD.

Support for uploading AVIF was added in [57524]. A new block of conditional logic was added determine which function should be used to create the new image file that resulted in these expensive functions being run twice.

This combines the two conditional logic to ensure the appropriate function is only run once regardless of format.

Props adamsilverstein, glynnquelch.
Fixes #62331.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-image-editor-gd.php

    r59406 r59413  
    104104        }
    105105
    106         // WebP may not work with imagecreatefromstring().
     106        // Handle WebP and AVIF mime types explicitly, falling back to imagecreatefromstring.
    107107        if (
    108             function_exists( 'imagecreatefromwebp' ) &&
    109             ( 'image/webp' === wp_get_image_mime( $this->file ) )
     108            function_exists( 'imagecreatefromwebp' ) && ( 'image/webp' === wp_get_image_mime( $this->file ) )
    110109        ) {
    111110            $this->image = @imagecreatefromwebp( $this->file );
    112         } else {
    113             $this->image = @imagecreatefromstring( $file_contents );
    114         }
    115 
    116         // AVIF may not work with imagecreatefromstring().
    117         if (
    118             function_exists( 'imagecreatefromavif' ) &&
    119             ( 'image/avif' === wp_get_image_mime( $this->file ) )
     111        } elseif (
     112            function_exists( 'imagecreatefromavif' ) && ( 'image/avif' === wp_get_image_mime( $this->file ) )
    120113        ) {
    121114            $this->image = @imagecreatefromavif( $this->file );
Note: See TracChangeset for help on using the changeset viewer.