From 9fe9f80823b4fc61cd4bc1932eaefaf505060c0a Mon Sep 17 00:00:00 2001 From: salty-ivy Date: Sat, 8 Jul 2023 17:16:43 +0100 Subject: [PATCH] Update documentation for AVIF support --- docs/guide/save.rst | 14 ++++++++++++-- docs/reference.rst | 15 +++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/docs/guide/save.rst b/docs/guide/save.rst index 751732c..d391972 100644 --- a/docs/guide/save.rst +++ b/docs/guide/save.rst @@ -7,6 +7,10 @@ In Willow there are separate save operations for each image format: - :meth:`~Image.save_as_png` - :meth:`~Image.save_as_gif` - :meth:`~Image.save_as_webp` + - :meth:`~Image.save_as_svg` + - :meth:`~Image.save_as_heic` + - :meth:`~Image.save_as_avif` + All three take one positional argument, the file-like object to write the image data to. @@ -46,14 +50,20 @@ can force Willow to always save a "progressive" JPEG file by setting the with open('progressive.jpg', 'wb') as f: i.save_as_jpeg(f, progressive=True) -Lossless WebP +Lossless AVIF, HEIC and WebP ----------------- -You can encode the image to WebP without any loss by setting the +You can encode the image to AVIF, HEIC (Pillow-only) and WebP without any loss by setting the ``lossless`` keyword argument to ``True``: .. code-block:: python + with open('lossless.avif', 'wb') as f: + i.save_as_avif(f, lossless=True) + + with open('lossless.heic', 'wb') as f: + i.save_as_heic(f, lossless=True) + with open('lossless.webp', 'wb') as f: i.save_as_webp(f, lossless=True) diff --git a/docs/reference.rst b/docs/reference.rst index 1c8b86a..23445ac 100644 --- a/docs/reference.rst +++ b/docs/reference.rst @@ -291,6 +291,21 @@ Here's a full list of operations provided by Willow out of the box: image.save_as_heic(f) +.. method:: save_as_avif(file, quality=80, lossless=False) + + (requires the pillow-heif library) + + Saves the image to the specified file-like object in AVIF format. + When saving with `lossless=True`, the `quality` value is set to `-1` and `chroma` to `444`. + + returns a ``AvifImageFile`` wrapping the file. + + .. code-block:: python + + with open('out.avif', 'wb') as f: + image.save_as_avif(f) + + .. method:: save_as_svg(file) (SVG images only)