Skip to content

Commit

Permalink
Media: Avoid running expensive logic twice using GD.
Browse files Browse the repository at this point in the history
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.

git-svn-id: https://develop.svn.wordpress.org/branches/6.7@59423 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
desrosj committed Nov 19, 2024
1 parent 7f37035 commit a431526
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/wp-includes/class-wp-image-editor-gd.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,13 @@ public function load() {
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 (
function_exists( 'imagecreatefromwebp' ) &&
( 'image/webp' === wp_get_image_mime( $this->file ) )
function_exists( 'imagecreatefromwebp' ) && ( 'image/webp' === wp_get_image_mime( $this->file ) )
) {
$this->image = @imagecreatefromwebp( $this->file );
} else {
$this->image = @imagecreatefromstring( $file_contents );
}

// AVIF may not work with imagecreatefromstring().
if (
function_exists( 'imagecreatefromavif' ) &&
( 'image/avif' === wp_get_image_mime( $this->file ) )
} elseif (
function_exists( 'imagecreatefromavif' ) && ( 'image/avif' === wp_get_image_mime( $this->file ) )
) {
$this->image = @imagecreatefromavif( $this->file );
} else {
Expand Down

0 comments on commit a431526

Please sign in to comment.