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.

Reviewed by adamsilverstein.
Merges [59413] to the 6.7 branch.

Props adamsilverstein, glynnquelch.
Fixes #62331.
Built from https://develop.svn.wordpress.org/branches/6.7@59423


git-svn-id: http://core.svn.wordpress.org/branches/6.7@58809 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
desrosj 2024-11-19 20:23:19 +00:00
parent 226f7f7964
commit 7aaf81c7cc
2 changed files with 5 additions and 12 deletions

View File

@ -103,20 +103,13 @@ class WP_Image_Editor_GD extends WP_Image_Editor {
return new WP_Error( 'error_loading_image', __( 'File does not exist?' ), $this->file ); return new WP_Error( 'error_loading_image', __( 'File does not exist?' ), $this->file );
} }
// WebP may not work with imagecreatefromstring(). // Handle WebP and AVIF mime types explicitly, falling back to imagecreatefromstring.
if ( if (
function_exists( 'imagecreatefromwebp' ) && function_exists( 'imagecreatefromwebp' ) && ( 'image/webp' === wp_get_image_mime( $this->file ) )
( 'image/webp' === wp_get_image_mime( $this->file ) )
) { ) {
$this->image = @imagecreatefromwebp( $this->file ); $this->image = @imagecreatefromwebp( $this->file );
} else { } elseif (
$this->image = @imagecreatefromstring( $file_contents ); function_exists( 'imagecreatefromavif' ) && ( 'image/avif' === wp_get_image_mime( $this->file ) )
}
// AVIF may not work with imagecreatefromstring().
if (
function_exists( 'imagecreatefromavif' ) &&
( 'image/avif' === wp_get_image_mime( $this->file ) )
) { ) {
$this->image = @imagecreatefromavif( $this->file ); $this->image = @imagecreatefromavif( $this->file );
} else { } else {

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.7.1-alpha-59421'; $wp_version = '6.7.1-alpha-59423';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.