compression quality toggle
Feature Description
there should be a compression quality setting - perhaps walled being an "advanced" mode toggle, or some override via a hook in functions or something -sure that's possible currently, though i'm a novice in this regard.
this was prompted because the current compression on webp (and even far more on avif) is overly agressive, and, in our use case compromises too much detail (grainy textures become soft and blurry).
@westonruter We could add new settings to the Media Settings page where we have already added some settings.
Should we add a toggle Image Compression which will be enabled by default or should we give a numeric input field to set the quality?
There is a filter for this actually:
// Use a quality setting of 75 for AVIF images.
function filter_avif_quality( $quality, $mime_type ) {
if ( 'image/avif' === $mime_type ) {
return 75;
}
return $quality;
}
add_filter( 'wp_editor_set_quality', 'filter_avif_quality', 10, 2 );
See the dev note from @adamsilverstein.
@westonruter does this pertain to either format - avif or webp?
@sweetrobot I believe you can filter WebP similarly:
function filter_webp_quality( $quality, $mime_type ) {
if ( 'image/webp' === $mime_type ) {
return 75;
}
return $quality;
}
add_filter( 'wp_editor_set_quality', 'filter_webp_quality', 10, 2 );
this was prompted because the current compression on webp (and even far more on avif) is overly agressive, and, in our use case compromises too much detail (grainy textures become soft and blurry).
Interesting - the default quality settings are actually pretty high already so I am a bit surprised to hear that. If possible, I would love to see some before/after images where this is happening. ie if you can, please provide a sample image and the webp / avif versions that look poor to you.
As @westonruter pointed out above, compression quality is already adjustable via filters so adding UI controls for them isn't a high priority (although I am not fundamentally opposed to adding them in the plugin). Also note that starting WordPress 6.8, the filter will include size values so quality can be set on a per-size basis. See https://core.trac.wordpress.org/ticket/54648.
@adamsilverstein please see following for comparisons. focus especially on the wooden frame, at 100% of course.
- video - download locally, to ensure highest quality before viewing - even with the added layer of video compression, the difference is still fully noticeable
- original
- webp @ 82
- webp @ 95
in cases such as ours, fine texture details are key, and the current default setting of 82 is too aggressive
- video - download locally, to ensure highest quality before viewing - even with the added layer of video compression, the difference is still fully noticeable
Even with downloading the original video file for viewing with the highest quality, the difference between the two is not fully noticeable to me. I mean, I see a difference but not really a difference in quality. The WebP version seems to have less noise, which I wouldn't say is worse. This is all subjective though.
@westonruter refer to the photos - swapping back and forth repeatedly, and focus on the grain (wood, rather than noise). much detail become smeared and lost entirely.
i only brought it up because i noticed the quality difference - this is without looking for it in the first place. it just hit me, because it was noticeable to me, even without the immediate back and forth flickering to compare.
i understand subjectivity plays a role, to a degree, but believe this is more than that.