Register 'avif' format when available in Pillow by AndrGutierrez · Pull Request #30363 · matplotlib/matplotlib · GitHub
Skip to content
2 changes: 2 additions & 0 deletions lib/matplotlib/backend_bases.py
20 changes: 18 additions & 2 deletions lib/matplotlib/backends/backend_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from math import radians, cos, sin

import numpy as np
from PIL import features

import matplotlib as mpl
from matplotlib import _api, cbook
Expand Down Expand Up @@ -510,18 +511,33 @@ def print_tif(self, filename_or_obj, *, metadata=None, pil_kwargs=None):
def print_webp(self, filename_or_obj, *, metadata=None, pil_kwargs=None):
self._print_pil(filename_or_obj, "webp", pil_kwargs, metadata)

print_gif.__doc__, print_jpg.__doc__, print_tif.__doc__, print_webp.__doc__ = map(
def print_avif(self, filename_or_obj, *, metadata=None, pil_kwargs=None):
if not features.check("avif"):
raise RuntimeError(
"The installed pillow version does not support avif. Full "
"avif support has been added in pillow 11.3."
)
self._print_pil(filename_or_obj, "avif", pil_kwargs, metadata)
Comment thread
AndrGutierrez marked this conversation as resolved.

(print_gif.__doc__,
print_jpg.__doc__,
print_tif.__doc__,
print_webp.__doc__,
print_avif.__doc__) = map(
"""
Write the figure to a {} file.

Parameters
----------
filename_or_obj : str or path-like or file-like
The file to write to.
metadata : None
Unused for pillow-based writers. All supported options
can be passed via *pil_kwargs*.
pil_kwargs : dict, optional
Comment thread
AndrGutierrez marked this conversation as resolved.
Additional keyword arguments that are passed to
`PIL.Image.Image.save` when saving the figure.
""".format, ["GIF", "JPEG", "TIFF", "WebP"])
""".format, ["GIF", "JPEG", "TIFF", "WebP", "AVIF"])


@_Backend.export
Expand Down
23 changes: 23 additions & 0 deletions lib/matplotlib/tests/test_agg.py
Loading