Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ As neither Pillow nor Wand support detecting faces, Willow would automatically c
| `save_as_gif(file)` | ✓ | ✓ | |
| `save_as_webp(file, quality)` | ✓ | ✓ | |
| `save_as_heic(file, quality, lossless)` | ✓⁺ | | |
| `save_as_avif(file, quality, lossless)` | ✓ | ✓ | |
| `save_as_avif(file, quality, lossless)` | ✓ | ✓ | |
| `save_as_ico(file)` | ✓ | ✓ | |
| `has_alpha()` | ✓ | ✓ | ✓\* |
| `has_animation()` | ✓\* | ✓ | ✓\* |
Expand Down
6 changes: 3 additions & 3 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ Note that Pillow doesn't support animated GIFs and Wand isn't as fast.
Installing both will give best results.


HEIC and AVIF support
^^^^^^^^^^^^^^^^^^^^^
HEIC support
^^^^^^^^^^^^

When using Pillow, you need to install ``pillow-heif`` for AVIF and HEIC support:
When using Pillow, you need to install ``pillow-heif`` for HEIC support:

.. code-block:: shell

Expand Down
2 changes: 1 addition & 1 deletion docs/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ Here's a full list of operations provided by Willow out of the box:
(requires the `pillow-heif <https://pypi.org/project/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`.
When saving with `lossless=True`, no `chroma subsampling <https://en.wikipedia.org/wiki/Chroma_subsampling>` is used (4:4:4 instead of the default 4:2:0).

returns a ``AvifImageFile`` wrapping the file.

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dependencies = [
]

[project.optional-dependencies]
pillow = ["Pillow>=9.1.0,<12.0.0"]
pillow = ["Pillow>=11.2.0,<12.0.0"]
wand = ["Wand>=0.6,<1.0"]
heif = [
"pillow-heif>=0.10.0,<1.0.0; python_version < '3.12'",
Expand Down
9 changes: 7 additions & 2 deletions willow/plugins/pillow.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from io import BytesIO

try:
from pillow_heif import AvifImagePlugin, HeifImagePlugin # noqa: F401
from pillow_heif import HeifImagePlugin # noqa: F401
except ImportError:
pass

Expand Down Expand Up @@ -425,7 +425,12 @@ def save_as_heic(
def save_as_avif(self, f, quality=80, lossless=False, apply_optimizers=True):
kwargs = {"quality": quality}
if lossless:
kwargs = {"quality": -1, "chroma": 444}
kwargs = {
# Quality of 100 implies lossless (according to libavif documentation)
"quality": 100,
# When encoding lossless images, don't use chroma subsampling (4:4:4 retains the most information)
"subsampling": "4:4:4",
Copy link
Member Author

@Stormheg Stormheg Apr 1, 2025

Choose a reason for hiding this comment

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

This isn't a valid option when encoding a grayscale image, should be 4:0:0 instead (grayscale is Pillow L or LA mode image) - something for a follow up?

Copy link
Collaborator

Choose a reason for hiding this comment

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

let's do it as a follow up (as long as you have the time :D)

Copy link
Member Author

Choose a reason for hiding this comment

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

Tried writing a failing test but it turns out save_as_avif will convert from LA to RGBA internally - which makes this not really relevant... or at least not without same yak shaving to figure out why the conversion is happening.

Let's leave this here for now.

}

image = self.image
icc_profile = self.get_icc_profile()
Expand Down