Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AVIF support #1314

Closed
allantatter opened this issue Sep 10, 2020 · 37 comments · Fixed by #1476
Closed

AVIF support #1314

allantatter opened this issue Sep 10, 2020 · 37 comments · Fixed by #1476

Comments

@allantatter
Copy link

Could AVIF support expected to be added at some point similarly to webp in format filters?

@franek
Copy link

franek commented Sep 21, 2020

Hi,
We would really appreciate that Thumbor does support AVIF format.

@fdintino
Copy link
Contributor

I opened python-pillow/Pillow#5201, which would make it possible for thumbor to support the format.

@Tsouef
Copy link

Tsouef commented Jul 8, 2021

Any news ?

@gladson
Copy link

gladson commented Jul 22, 2021

https://github.com/libvips/libvips

It supports a good range of image formats, including JPEG, JPEG2000, JPEG-XL, TIFF, PNG, WebP, HEIC, AVIF, FITS, Matlab, OpenEXR, PDF, SVG, HDR, PPM / PGM / PFM, CSV, GIF, Analyze, NIfTI, DeepZoom, and OpenSlide.

@scorphus
Copy link
Member

scorphus commented Jul 22, 2021

You can try the ImageMagick engine. You'll need Thumbor from master, though. Let me know if it works, please.

@fdintino
Copy link
Contributor

It's been taking a while to get the pillow PR merged. To be fair to the pillow developers, it's not a trivial new feature. Until that PR lands I've created a standalone package, pillow-avif-plugin, that adds AVIF support to Pillow. Also, unlike my pillow PR—which only works in python 3—my standalone package has wheels built against python 2. This is because the latest stable version of thumbor is still python 2-only.

I'm currently testing out an extension of thumbor and thumbor-video-engine on https://www.theatlantic.com/ that adds auto-AVIF support. If you visit the site in chrome, you'll see a bunch of AVIF images being served in the Network tab in the web inspector. The source code for that isn't publicly available, but if it goes well I'm planning on creating a package for it.

@vanchung1995
Copy link

@fdintino I have used pillow avif plugin, it worked nice. But I dont know how to apply it into thumbor. Example I want to crop image, then convert it to avif image. I read a lots but nothing found. Can you give some guide? Thanks so much

@heynemann
Copy link
Member

Do you know whether browsers inform whether they support AVIF using the accepts header?

@fdintino
Copy link
Contributor

fdintino commented Oct 7, 2021

Chrome supports image/avif, and has it in the Accept headers for images. And Firefox does as well if the experimental flag is enabled.

Sorry I haven't posted an update here yet. The code required to extend the auto_webp functionality to auto_avif isn't trivial: you need to extend ThumborServiceApp with a class that replaces the ImagingHandler in get_handlers so you can access the headers. In the handler class you need to set context.request.accepts_avif. And you need to extend the logic in _write_results_to_client so that it adds Vary: Accept for auto-avif-capable images.

On top of that you need a custom image engine that allows you to control things like the quality and codec of the AVIF encode via settings. And you need to make sure that the result_storage stores the auto-avif images in a separate location (whether that's the file_storage or tc_aws).

I've also written code to use the thumbor threadpool to perform the AVIF encoding in the background. The first time an AVIF image is requested for an auto-avif capable image, it returns whatever non-AVIF format would be the default (with a short cache TTL) while it queues up a background encode. Once the encoding is complete in the background thread, it saves the AVIF image to result storage, after which point requests for that image that Accept: image/avif get served the image from storage.

I ran into some oddities while working on this feature. For instance: Chrome will happily serve up a JPEG image that's encoded with 3 RGB channels but has a CMYK color profile, but it will refuse to do the same for an AVIF image (which has YUV channels). Images that have RGB data but CMYK color profiles are probably pretty uncommon generally, but they crop up fairly often when you're working with images that were originally intended for print. So I had to write a function that checks the color profile and transforms it to sRGB if necessary.

All of which is to say that there's still some work to do (mainly documentation and packaging) before it can be published in a public repository. But I still intend to do so.

@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove the stale label or add a comment, or this issue will be closed in 5 days. You can always re-open if you still feel this is still an issue. Tag @heynemann for more information.

@github-actions github-actions bot added the Stale label Jan 22, 2022
@mvhirsch
Copy link
Contributor

AVIF is spreading, see https://caniuse.com/?search=avif

Bumping this issue (stale-bot 🎉 )

@github-actions github-actions bot removed the Stale label Jan 23, 2022
@heynemann
Copy link
Member

I will bootcamp this task later. This seems like a good L3 task.

@fdintino
Copy link
Contributor

@heynemann Adding avif directly to thumbor as a PR would certainly be easier for me than maintaining an extension, if that's something you would welcome

@heynemann
Copy link
Member

I would @fdintino but we will probably revamp how we handle alternate image formats to remove webp as a special case and just let web formats be extensible. I think that's a better point to add than to just add a bunch more if-else statements (we do have enough of those as it is).

@github-actions
Copy link

github-actions bot commented Mar 3, 2022

This issue is stale because it has been open 30 days with no activity. Remove the stale label or add a comment, or this issue will be closed in 5 days. You can always re-open if you still feel this is still an issue. Tag @heynemann for more information.

@github-actions github-actions bot added the Stale label Mar 3, 2022
@fdintino
Copy link
Contributor

fdintino commented Mar 3, 2022

@heynemann would you be open to my attempting such a refactor and opening it as a PR? I've written code for theatlantic.com that supports auto-webp, auto-avif, and auto-h265 (for animated gifs on safari). It's not open source, largely because it's such a hack. But the experience of extending thumbor to support it has made me pretty familiar with the auto-convert code, and has given me an understanding of where the pain-points are.

@heynemann
Copy link
Member

Definitely!!!

@github-actions github-actions bot removed the Stale label Mar 4, 2022
@Sinitra
Copy link

Sinitra commented Mar 28, 2022

@heynemann would you be open to my attempting such a refactor and opening it as a PR? I've written code for theatlantic.com that supports auto-webp, auto-avif, and auto-h265 (for animated gifs on safari). It's not open source, largely because it's such a hack. But the experience of extending thumbor to support it has made me pretty familiar with the auto-convert code, and has given me an understanding of where the pain-points are.

share your code, let's taste it

@markatli
Copy link

@heynemann Would love to see it as well! Thank you!

@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove the stale label or add a comment, or this issue will be closed in 5 days. You can always re-open if you still feel this is still an issue. Tag @heynemann for more information.

@github-actions github-actions bot added the Stale label May 21, 2022
@fdintino
Copy link
Contributor

Posting a comment to keep this issue open.

@Sinitra
Copy link

Sinitra commented May 22, 2022

Posting a comment to keep this issue open.

+1

@github-actions github-actions bot removed the Stale label May 23, 2022
@relliv
Copy link

relliv commented Jun 2, 2022

Still need.

@beeremy
Copy link

beeremy commented Jun 9, 2022

+1

2 similar comments
@bbodinat
Copy link

+1

@schappim
Copy link

+1

@acusti
Copy link

acusti commented Jul 27, 2022

just wanted to mention that macOS Ventura and iOS 16 have added support for AVIF. this means Safari 16 will support AVIF on latest macOS and iOS, which is gonna bump global browser support (currently 71%) to well over 80%. i think this makes support for AVIF pretty critical and only increasing in importance from here forward.

@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove the stale label or add a comment, or this issue will be closed in 5 days. You can always re-open if you still feel this is still an issue. Tag @heynemann for more information.

@github-actions github-actions bot added the Stale label Aug 12, 2022
@cortopy
Copy link

cortopy commented Aug 12, 2022

commenting to keep active

@fdintino
Copy link
Contributor

I've opened #1476 to add AVIF encoding. It doesn't have any auto-avif features, but once AVIF encoding is generally supported that might be a good test case for the plugin proposal in #1446

@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove the stale label or add a comment, or this issue will be closed in 15 days. You can always re-open if you still feel this is still an issue. Tag @heynemann for more information.

@github-actions github-actions bot added the Stale label Sep 17, 2022
@relliv
Copy link

relliv commented Sep 17, 2022

I think this issue need be keep open.

@github-actions github-actions bot removed the Stale label Sep 18, 2022
@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove the stale label or add a comment, or this issue will be closed in 15 days. You can always re-open if you still feel this is still an issue. Tag @heynemann for more information.

@schappim
Copy link

bump

@acusti
Copy link

acusti commented Oct 18, 2022

pretty cool to see the stale bot resulting in a PR being revived! #1476 (comment)

@RaphaelVRossi
Copy link
Member

You can now use this feature here Release 7.2.0

Thank you @fdintino 🚀

@frasko23
Copy link

cool!
So one question does this soluction fit into Google images since avif format it is not supported directly by googlei mages..?

So i guess there should be a dynamic thumbor response to serve webp/jpeg/gif to google image bot?

Or is possible in frontend a way to fit in html the fallback in
https://codelabs.developers.google.com/codelabs/avif#4

?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.