diff options
Diffstat (limited to 'wp-includes/class-wp-image-editor-imagick.php')
-rw-r--r-- | wp-includes/class-wp-image-editor-imagick.php | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/wp-includes/class-wp-image-editor-imagick.php b/wp-includes/class-wp-image-editor-imagick.php index 03fe0bc..5de01d7 100644 --- a/wp-includes/class-wp-image-editor-imagick.php +++ b/wp-includes/class-wp-image-editor-imagick.php @@ -219,6 +219,7 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor { $this->image->setImageCompressionQuality( $quality ); } break; + case 'image/avif': default: $this->image->setImageCompressionQuality( $quality ); } @@ -256,6 +257,16 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor { $height = $size['height']; } + /* + * If we still don't have the image size, fall back to `wp_getimagesize`. This ensures AVIF images + * are properly sized without affecting previous `getImageGeometry` behavior. + */ + if ( ( ! $width || ! $height ) && 'image/avif' === $this->mime_type ) { + $size = wp_getimagesize( $this->file ); + $width = $size[0]; + $height = $size[1]; + } + return parent::update_size( $width, $height ); } @@ -478,10 +489,6 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor { $this->image->setImageDepth( 8 ); } } - - if ( is_callable( array( $this->image, 'setInterlaceScheme' ) ) && defined( 'Imagick::INTERLACE_NO' ) ) { - $this->image->setInterlaceScheme( Imagick::INTERLACE_NO ); - } } catch ( Exception $e ) { return new WP_Error( 'image_resize_error', $e->getMessage() ); } @@ -814,6 +821,20 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor { return new WP_Error( 'image_save_error', $e->getMessage(), $filename ); } + if ( method_exists( $this->image, 'setInterlaceScheme' ) + && method_exists( $this->image, 'getInterlaceScheme' ) + && defined( 'Imagick::INTERLACE_PLANE' ) + ) { + $orig_interlace = $this->image->getInterlaceScheme(); + + /** This filter is documented in wp-includes/class-wp-image-editor-gd.php */ + if ( apply_filters( 'image_save_progressive', false, $mime_type ) ) { + $this->image->setInterlaceScheme( Imagick::INTERLACE_PLANE ); // True - line interlace output. + } else { + $this->image->setInterlaceScheme( Imagick::INTERLACE_NO ); // False - no interlace output. + } + } + $write_image_result = $this->write_image( $this->image, $filename ); if ( is_wp_error( $write_image_result ) ) { return $write_image_result; @@ -822,6 +843,10 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor { try { // Reset original format. $this->image->setImageFormat( $orig_format ); + + if ( isset( $orig_interlace ) ) { + $this->image->setInterlaceScheme( $orig_interlace ); + } } catch ( Exception $e ) { return new WP_Error( 'image_save_error', $e->getMessage(), $filename ); } |