Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/wp-includes/class-wp-image-editor-imagick.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,11 @@ public function load() {
}

$this->mime_type = $this->get_mime_type( $this->image->getImageFormat() );

// ImageMagick 6 can report an AVIF image as HEIC when using the libheif delegate.
if ( wp_is_heic_image_mime_type( $this->mime_type ) && 'image/avif' === wp_get_image_mime( $this->file ) ) {
$this->mime_type = 'image/avif';
}
} catch ( Exception $e ) {
return new WP_Error( 'invalid_image', $e->getMessage(), $this->file );
}
Expand Down
23 changes: 23 additions & 0 deletions tests/phpunit/tests/image/editorImagick.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,29 @@ public function test_supports_mime_type() {
$this->assertTrue( $imagick_image_editor->supports_mime_type( 'image/gif' ), 'Does not support image/gif' );
}

/**
* AVIF output should retain its format even when Imagick identifies the source as HEIC.
*
* @ticket 66261
*/
public function test_avif_output_format_retained() {
if ( ! WP_Image_Editor_Imagick::supports_mime_type( 'image/avif' ) ) {
$this->markTestSkipped( 'Imagick does not support AVIF.' );
}

$editor = new WP_Image_Editor_Imagick( DIR_TESTDATA . '/images/avif-lossy.avif' );
$this->assertTrue( $editor->load() );

$get_output_format = new ReflectionMethod( $editor, 'get_output_format' );
if ( PHP_VERSION_ID < 80100 ) {
$get_output_format->setAccessible( true );
}

list( , $extension, $mime_type ) = $get_output_format->invoke( $editor );
$this->assertSame( 'avif', $extension );
$this->assertSame( 'image/avif', $mime_type );
}

/**
* Tests resizing an image, not using crop.
*/
Expand Down
Loading