performance icon indicating copy to clipboard operation
performance copied to clipboard

Modern Image Formats: add AVIF output support

Open adamsilverstein opened this issue 1 year ago • 5 comments

Summary

Add AVIF support for Modern Image Formats plugin.

Fixes https://github.com/WordPress/performance/issues/1151

Relevant technical choices

  • When the server supports AVIF, add a dropdown under settings->media where users can choose between AVIF and WebP as the output format
  • Slightly rename the field that enables generating JPEG images alongside the modern output format (so it isn't just about WebP plug JPEG).
    • note: I left the option name unchanged for backwards compatibility.
  • I removed the CSS class that were hiding part of the settings UI, that felt hacky and made adding the new field more challenging.

Screenshots

Media settings

The new settings fields on media, the new dropdown is only shown if AVIF is supported on the server:

image

note: the default selection is AVIF when available.

Uploads

  • Note: activate twenty-twentyone theme

Output set to AVIF

image

Output set to WebP

image

With "Also Output JPEGs" checked

AVIF

image

WebP

image

Note: there appears to be a bug when the additional JPEG option is selected. I will double check, I believe this problem is already present in trunk. Looking carefully at the final two images where this setting is enabled, the AVIF/WebP images are only generated in the default (small/medium/medium/large/large and -scaled) variations it looks like custom sizes and maybe the high dpi images are missing in the modern format. I can create a separate issue to investigate this further.

adamsilverstein avatar Apr 23 '24 21:04 adamsilverstein

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

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

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: phanduynam.

Co-authored-by: adamsilverstein <[email protected]>
Co-authored-by: westonruter <[email protected]>
Co-authored-by: joemcgill <[email protected]>

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

github-actions[bot] avatar Apr 23 '24 21:04 github-actions[bot]

It would be good to add some tests here. I was expecting existing tests to fail, since I changed the default output to AVIF - maybe the test runners don't have AVIF support.

adamsilverstein avatar Apr 25 '24 13:04 adamsilverstein

I'm going to work on expanding the tests to cover both WebP and AVIF output.

adamsilverstein avatar May 01 '24 19:05 adamsilverstein

Still working on tests for AVIF here, I also started working on making the fallback script more flexible so it will work for either AVIF or WebP.

Related: https://github.com/WordPress/performance/issues/469 & https://github.com/WordPress/performance/issues/996

adamsilverstein avatar May 02 '24 15:05 adamsilverstein

Tests were failing with PHP 8.0 because some environments report AVIF support when in fact they do not support AVIF, see https://github.com/php/php-src/issues/12197. To get tests passing locally, I made the check for AVIF support more robust.

adamsilverstein avatar May 03 '24 14:05 adamsilverstein

Notice warning users their server lacks AVIF support. Language borrowed from Health Check for AVIF image

AVIF disabled in the dropdown due to lack of server support. image

adamsilverstein avatar May 06 '24 21:05 adamsilverstein

While testing the fallback script locally I noticed that if I check the box to output JPEG as well as WebP or AVIF, the output HTML lacks the srcset I expect to see. Unchecking the box, the srcset returns.

Looking at the generated meta data, it seems fine so I am going to dig further. I don't think this is the intended behavior. Maybe @mukeshpanchal27 knows, did this previously work with the full srcset here?

adamsilverstein avatar May 07 '24 16:05 adamsilverstein

While testing the fallback script locally I noticed that if I check the box to output JPEG as well as WebP or AVIF, the output HTML lacks the srcset I expect to see. Unchecking the box, the srcset returns.

I tested this with the current shipping plugin and observed the same issue, so this is unrelated to the changes in this PR. I searched and didn't find an existing issue for this, so I will go ahead and open one.

adamsilverstein avatar May 07 '24 17:05 adamsilverstein

While testing the fallback script locally I noticed that if I check the box to output JPEG as well as WebP or AVIF, the output HTML lacks the srcset I expect to see. Unchecking the box, the srcset returns.

I tested this with the current shipping plugin and observed the same issue, so this is unrelated to the changes in this PR. I searched and didn't find an existing issue for this, so I will go ahead and open one.

I created this issue to investigate separately: https://github.com/WordPress/performance/issues/1207

adamsilverstein avatar May 07 '24 18:05 adamsilverstein

These assertIsArray assertions were removed in #1203 (pending merge) since they are now redundant, so they can be removed here too.

westonruter avatar May 07 '24 21:05 westonruter

This is close, needs some additional testing.

adamsilverstein avatar May 08 '24 23:05 adamsilverstein

Do the current modifications help convert PNG to Avif/Webp on upload?

phanduynam avatar May 09 '24 16:05 phanduynam

Do the current modifications help convert PNG to Avif/Webp on upload?

@phanduynam - not currently, however you can add this using a simple filter, see this comment for details: https://github.com/WordPress/performance/issues/371#issuecomment-2050294385

adamsilverstein avatar May 09 '24 18:05 adamsilverstein

Noting that I manually verified the fallback script works as expected (with the caveat that the srcset is not being output correctly when the JPEG generation is enabled.

adamsilverstein avatar May 10 '24 20:05 adamsilverstein

when the JPEG generation is enabled.

Also: should we skip doing the detection at all is this is disabled since presumably there will be no fallback?

adamsilverstein avatar May 10 '24 20:05 adamsilverstein

Is the Avif image format version you are using the latest Avif 1.1.0 version?

https://aomediacodec.github.io/av1-avif/ https://aomediacodec.github.io/av1-avif/#change-list

phanduynam avatar May 11 '24 01:05 phanduynam

🎉

"At least 1 approving review is required to merge this pull request."

adamsilverstein avatar May 29 '24 14:05 adamsilverstein

🎉

"At least 1 approving review is required to merge this pull request."

https://github.com/WordPress/performance/pull/1257 should let you approve this one @westonruter

adamsilverstein avatar May 29 '24 14:05 adamsilverstein

Is the AVIF image file format version being used the latest version 1.1.0 as described below? https://aomediacodec.github.io/av1-avif/

phanduynam avatar May 31 '24 01:05 phanduynam