#61614 closed defect (bug) (fixed)
Media: Ensure Imagick quality is set correctly
Reported by: | adamsilverstein | Owned by: | adamsilverstein |
---|---|---|---|
Milestone: | 6.7 | Priority: | normal |
Severity: | normal | Version: | 6.5 |
Component: | General | Keywords: | has-patch commit has-unit-tests |
Focuses: | Cc: |
Description
Summary
Imagick does not properly set image quality for AVIF images.
A user reported an issue in the Performance Lab plugin "wp_editor_set_quality not changing image quality for AVIF images". Link: https://github.com/WordPress/performance/issues/1331. When investigating this issue I found that the quality setting being applied in core doesn't work correctly when outputting AVIF images. When we added AVIF support in 6.5 we suggested using the wp_editor_set_quality
filter control the AVIF quality setting, but this currently doesn't work (at least with Imagick).
Steps to reproduce
Here are the testing instructions:
- Test on a server with Imagick enabled AVIF support. Check under Tools->Siet Health->Info to verify Imagick has AVIF in list of supported types.
- Upload an AVIF image, verify all of the sub-sized (AVIF) images are created.
- Add the following code snippet in your theme or an mu plugin:
function filter_avif_quality( $quality, $mime_type ) { if ( 'image/avif' === $mime_type ) { return 15; } return $quality; } add_filter( 'wp_editor_set_quality', 'filter_avif_quality', 10, 2 );
- Upload the same image as in step 2. the filter should be applied and the very low quality (15) should be used.
- Expected result: the generated AVIF images are much smaller sized and lower quality looking (noticeable artifacts).Actual result: the generated images from step 2 are the same as the images generated in step 4 - the quality setting has no effect.
Previous Discussion
In this post the author encounters the same issue. The answer that resolves the issue is below:
I found the solution, Thanks to Danack from Imagick https://github.com/Imagick/imagick/.
There are two functions to set the compression quality:
setImageCompressionQuality
setCompressionQuality
According to the online documentation
https://www.php.net/manual/en/imagick.setcompressionquality.php ... setCompressionQuality is for new images, and setImageCompressionQuality for already
existing ones.
Solution
I discovered that adding
$this->image->setCompressionQuality( $quality );
where we currently call setImageCompressionQuality
already fixes the issue.
I am not clear if this issue affects other formats in any way (it didn't in my initial testing). However adding the additional quality setting call seems like a safe change to add and this will fix the issue for AVIFs.
Attachments (1)
Change History (8)
This ticket was mentioned in PR #7004 on WordPress/wordpress-develop by @adamsilverstein.
6 months ago
#1
- Keywords has-patch added
#6
@
3 months ago
- Owner set to adamsilverstein
- Resolution set to fixed
- Status changed from new to closed
In 59247:
Trac ticket: https://core.trac.wordpress.org/ticket/61614