Skip to content

Use an AVIF quality equivalent to the default WebP quality - #2746

Open
b1ink0 wants to merge 3 commits into
WordPress:trunkfrom
b1ink0:fix/AVIF-image-filesize
Open

b1ink0 wants to merge 3 commits into
WordPress:trunkfrom
b1ink0:fix/AVIF-image-filesize

Conversation

@b1ink0

@b1ink0 b1ink0 commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #2745

Relevant technical choices

See the linked issue for more details on how this value was determined.

This PR sets the AVIF quality to 70 in webp_uploads_modify_webp_quality(), the same way the WebP quality is already pinned to 82.

At the default quality of 82, AVIF sub-sizes come out larger than WebP and often larger than the JPEG. With "Output fallback images" enabled, most AVIF sub-sizes were then discarded. Each encoder maps the 0 to 100 number to its own quantizer, so 82 is a much higher visual quality for AVIF than for WebP. Based on the measurements in the issue, AVIF at 70 is about the same quality as WebP at 82 and is smaller.

  • The value is set through the wp_editor_set_quality filter, which core calls with the output mime type. So one value covers GD, Imagick and client-side media processing, which reads the same filter through the image_quality REST field.
  • Tests check the AVIF quality with and without the plugin filter, for both GD and Imagick and for the REST response. They also check that every AVIF size is kept and is smaller than the JPEG fallback when "Output fallback images" is enabled. car.jpeg is used because at quality 70 its AVIF files are smaller than the JPEG at every size with both editors, while at 82 some sizes are not.

Sites without the plugin still get 82 from WP_Image_Editor::get_default_quality(), so core needs a follow-up ticket.

Use of AI Tools

Used Claude Code to trace the quality flow, run the benchmarks and write the change and tests. I reviewed the code and verified the results.

AVIF at quality 82 is often larger than WebP at 82, so with the JPEG
fallback on, AVIF sub-sizes were thrown away as larger than the JPEG.
At quality 70 AVIF looks about the same as WebP at 82 and is smaller.

The quality filter now returns 70 for AVIF. Because it runs on
wp_editor_set_quality, this applies to GD, Imagick and the REST
image_quality field used for browser-side uploads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@b1ink0 b1ink0 added this to the webp-uploads n.e.x.t milestone Nov 4, 2026
@b1ink0 b1ink0 added the [Plugin] Modern Image Formats Formerly WebP Uploads [slug: webp-uploads] label Nov 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @jakearchibald.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: jakearchibald.

Co-authored-by: b1ink0 <b1ink0@git.wordpress.org>
Co-authored-by: adamsilverstein <adamsilverstein@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@b1ink0
b1ink0 requested a review from westonruter November 4, 2026 17:02
@codecov

codecov Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.42%. Comparing base (23dd539) to head (e4b529d).

Additional details and impacted files
@@           Coverage Diff           @@
##            trunk    #2746   +/-   ##
=======================================
  Coverage   70.41%   70.42%           
=======================================
  Files          91       91           
  Lines        7869     7871    +2     
=======================================
+ Hits         5541     5543    +2     
  Misses       2328     2328           
Flag Coverage Δ
multisite 70.42% <100.00%> (+<0.01%) ⬆️
single 35.21% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@b1ink0 b1ink0 added the [Type] Bug An existing feature is broken label Nov 5, 2026
Comment thread plugins/webp-uploads/hooks.php Outdated
}

// Return default quality for non-WebP images in WP.
// AVIF at 82 is often larger than WebP at 82. AVIF at 70 looks about the same as WebP at 82 and is smaller.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious how these numbers was determined. They may be accurate, but "looks about the same" is vague. Consider adding some analysis like DSSIM or another more modern approach.

Comment thread plugins/webp-uploads/hooks.php Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

other types used 82? which ones?

Comment thread plugins/webp-uploads/hooks.php Outdated

// Return default quality for non-WebP images in WP.
// AVIF at 82 is often larger than WebP at 82. AVIF at 70 looks about the same as WebP at 82 and is smaller.
if ( 'image/avif' === $mime_type ) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be a switch statement at this point.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in b6d399f

@adamsilverstein

Copy link
Copy Markdown
Member

I'd like to see more research on the output quality before merging this. How did you arrive at these numbers. I support smaller files as long as we can be reasonable confident quality doesn't degrade over the default jpeg settings. I believe the formats are designed to (perhaps aspirationally) deliver the same quality at the same quality settings.

Also, maybe the quality default can be even lower for avif, see: https://www.industrialempathy.com/posts/avif-webp-quality-settings/

some related previous discussion: https://core.trac.wordpress.org/ticket/54356

@adamsilverstein

Copy link
Copy Markdown
Member

I see the research now on the issue, I missed it previously. See my comment there, big +1 to changing this here ASAP and also proposing for core. lets get these values as low as we can while matching jpeg's default 82 quality.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Plugin] Modern Image Formats Formerly WebP Uploads [slug: webp-uploads] [Type] Bug An existing feature is broken

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AVIF sub-sizes are larger than WebP at the default quality of 82

2 participants