Skip to content

FIX: ValueError: Format 'avif' is not supported #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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

AndrGutierrez
Copy link

@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
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.

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
3 participants