Skip to content

Register 'avif' format when available in Pillow #30363

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

Merged
merged 9 commits into from
Jul 30, 2025

Conversation

AndrGutierrez
Copy link
Contributor

@AndrGutierrez AndrGutierrez commented Jul 27, 2025

PR summary

closes #28809

This fixes the error
ValueError: Format 'avif' is not supported (supported formats: eps, jpeg, jpg, pdf, pgf, png, ps, raw, rgba, svg, svgz, tif, tiff, webp) mentioned when saving a .avif figure by doing fig.savefig('test.avif') .

I am not sure if I should add new tests for this, however I got the same results I got when merging the main branch so I would like feedback on that

PR checklist

@AndrGutierrez AndrGutierrez marked this pull request as ready for review July 28, 2025 01:11
@AndrGutierrez AndrGutierrez marked this pull request as draft July 28, 2025 02:20
@anntzer
Copy link
Contributor

anntzer commented Jul 28, 2025

I don't think we can merge this until we require Pillow 11.2.1 (the first version to support avif).
More generally, I also wonder whether it makes sense to add support in such a piecemeal fashion, or whether we should have a more general "forward-all-these-formats-to-pillow" mechanism... (does pillow allow listing the formats it supports?)

@timhoffm
Copy link
Member

timhoffm commented Jul 28, 2025

Well, the formats are not changing that often, so that piecemeal can be good enough. The problem with the version exists, but is bearable. People will get an error message if their pillow is too old. Maybe check if that message is good enough or whether we should provide a better message.

does pillow allow listing the formats it supports?

From a quick look, I did not see anything in the documentation, but AI suggests

# Get the list of supported formats for opening images
supported_open_formats = Image.OPEN.keys()

# Get the list of supported formats for saving images
supported_save_formats = Image.SAVE.keys()

would need investigation what exactly is in there and whether we can use it.

Edit: Actually, this can be done via PIL.features

@timhoffm
Copy link
Member

timhoffm commented Jul 28, 2025

Please add a test test_pil_kwargs_avif() similar to the existing test_pil_kwargs_* tests here

def test_pil_kwargs_png():

Note: Use the feature query like here to selectively skip the test

@pytest.mark.skipif(not features.check("webp"), reason="WebP support not available")

@AndrGutierrez
Copy link
Contributor Author

AndrGutierrez commented Jul 28, 2025

Ok so I added the test for transparency too, and the kwargs test is basically a copy of the webp test that checks compression quality and kwargs, tell me if there is anything else that should be tested in there.

@AndrGutierrez
Copy link
Contributor Author

Test for ubuntu ARM failed, is this a problem? it seems that it just disconnected, I doubt I made something that makes it fail

@AndrGutierrez AndrGutierrez marked this pull request as ready for review July 28, 2025 18:34
Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

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

Minor suggestions

AndrGutierrez and others added 5 commits July 29, 2025 15:25
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
@AndrGutierrez
Copy link
Contributor Author

Thank you so much for your feedback Tim :)

@AndrGutierrez
Copy link
Contributor Author

closed by accident lol

@AndrGutierrez AndrGutierrez reopened this Jul 29, 2025
Copy link
Member

@QuLogic QuLogic left a comment

Choose a reason for hiding this comment

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

Minor issues.

AndrGutierrez and others added 2 commits July 30, 2025 12:09
Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
@QuLogic QuLogic changed the title FIX: ValueError: Format 'avif' is not supported Register 'avif' format when available in Pillow Jul 30, 2025
@QuLogic QuLogic merged commit 4a60fac into matplotlib:main Jul 30, 2025
40 checks passed
@QuLogic QuLogic added this to the v3.11.0 milestone Jul 30, 2025
@QuLogic
Copy link
Member

QuLogic commented Jul 30, 2025

Thanks @AndrGutierrez! Congratulations on your first PR to Matplotlib 🎉 We hope to hear from you again.

@AndrGutierrez
Copy link
Contributor Author

It was a very nice experience, thank you for all the feedback, I will try to contribute more so ping me if there is something I there's something I can help with

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

Successfully merging this pull request may close these issues.

[ENH]: Support avif as output format
4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy