WordPress / performance

Performance plugin from the WordPress Performance Group, which is a collection of standalone performance modules.
https://wordpress.org/plugins/performance-lab/
GNU General Public License v2.0
340 stars 91 forks source link

wp_editor_set_quality not changing image quality for AVIF images #1331

Closed jamesozzie closed 5 days ago

jamesozzie commented 1 week ago

Bug Description

As raised by one user in the support forums, applying a wp_editor_set_quality filter has no effect to AVIF images generated by the plugin.

Steps to reproduce

  1. Download this JPEG image (120.78 KB in size, taken from here) and upload it with the AVIF format enabled. The compressed image should be 39KBs.
  2. Apply the wp_editor_set_quality filter, as per this guide, using the below example snippet.
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 );
  1. Upload the same JPEG image once more. The AVIF image size remains at 39KBs

Screenshots

Additional Context

mukeshpanchal27 commented 1 week ago

I also replicate same issue.

mukeshpanchal27 commented 6 days ago

It seems like the issue with AVIF image quality settings might be related to bugs within the WordPress Core or the library ImageMagick.

https://kiwix.ounapuu.ee/content/stackoverflow.com_en_all_2023-11/questions/73549733/php-imagick-avif-image-quality-options-not-working

@adamsilverstein @westonruter do we needs to open issue in WordPress Trac and close this one?

adamsilverstein commented 6 days ago

do we needs to open issue in WordPress Trac and close this one?

possibly, I will review and test further.

adamsilverstein commented 5 days ago

I also verified this bug, it seems like the core call to setImageCompressionQuality doesn't actually work and maybe this needs to be setCompressionQuality - testing further. I'm not sure if this is isolated to AVIFs or extends to other image types as well.

adamsilverstein commented 5 days ago

the code works fine when adjusting WebP quality, it fails with Imagick and AVIF. I'm going to search for possible upstream bugs.

adamsilverstein commented 5 days ago

I verified that this is fixed by adding a single line into core's Imagick editor class with setCompressionQuality in addition to setImageCompressionQuality. I'm not sure why PHP behaves differently with WebP vs. AVIF.

I will open a ticket to fix this in core, I think we should call $this->image->setCompressionQuality( $quality ); for all types.

adamsilverstein commented 5 days ago

Closing in favor of https://core.trac.wordpress.org/ticket/61614.

@jamesozzie @mukeshpanchal27 - if possible can you test the fix I am proposing there?