Skip to content

Change default file type to AVIF (Baseline 2024) #205

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 1 commit into from
Jul 1, 2025
Merged
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
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ PICTURES = {
},
"GRID_COLUMNS": 12,
"CONTAINER_WIDTH": 1200,
"FILE_TYPES": ["WEBP"],
"FILE_TYPES": ["AVIF"],
"PIXEL_DENSITIES": [1, 2],
"USE_PLACEHOLDERS": True,
"QUEUE_NAME": "pictures",
Expand Down Expand Up @@ -199,12 +199,6 @@ Baseline 2024 and is supported by all major browsers. Additionally, most modern
devices will have hardware acceleration for AVIF decoding. This will not only
reduce network IO but speed up page rendering.

> [!NOTE]
> Pillow 11.2.1 shipped without AVIF binaries.
> You will need to [install Pillow from source][libavif-install] for AVIF support.
> This should be resolved in upcoming releases, once
> [#8858](https://github.com/python-pillow/Pillow/pull/8858) has been merged.

Should you still serve IE11, use add `JPEG` to the list. But, beware, this may
drastically increase your storage needs.

Expand Down Expand Up @@ -256,7 +250,7 @@ from rest_framework import serializers
from pictures.contrib.rest_framework import PictureField

class PictureSerializer(serializers.Serializer):
picture = PictureField(aspect_ratios=["16/9"], file_types=["WEBP"])
picture = PictureField(aspect_ratios=["16/9"], file_types=["AVIF"])
```

You also may provide optional GET parameters to the serializer
Expand Down
2 changes: 1 addition & 1 deletion pictures/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def get_settings():
},
"GRID_COLUMNS": 12,
"CONTAINER_WIDTH": 1200,
"FILE_TYPES": ["WEBP"],
"FILE_TYPES": ["AVIF"],
"PIXEL_DENSITIES": [1, 2],
"USE_PLACEHOLDERS": settings.DEBUG,
"QUEUE_NAME": "pictures",
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ classifiers = [
"Framework :: Django :: 5.2",
]
requires-python = ">=3.9"
dependencies = ["django>=4.2.0", "pillow>=9.0.0"]
dependencies = ["django>=4.2.0", "pillow>=11.3.0"]

[project.optional-dependencies]
test = [
Expand Down
2 changes: 1 addition & 1 deletion tests/contrib/test_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_delete(self, stub_worker, image_upload_file):
stub_worker.join()

name = obj.picture.name
path = obj.picture.aspect_ratios["16/9"]["WEBP"][100].path
path = obj.picture.aspect_ratios["16/9"]["AVIF"][100].path
assert default_storage.exists(name)
assert path.exists()
with transaction.atomic(get_using(obj)):
Expand Down
200 changes: 100 additions & 100 deletions tests/contrib/test_rest_framework.py

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions tests/test_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class Meta:
migration = migrations.AlterPictureField("profile", "picture", PictureField())
from_field = Profile._meta.get_field("picture")

path = luke.picture.aspect_ratios["16/9"]["WEBP"][100].path
path = luke.picture.aspect_ratios["16/9"]["AVIF"][100].path
assert path.exists()

migration.update_pictures(from_field, ToModel)
Expand All @@ -143,7 +143,7 @@ class Meta:
luke.refresh_from_db()
path = (
ToModel.objects.get(pk=luke.pk)
.picture.aspect_ratios["21/9"]["WEBP"][100]
.picture.aspect_ratios["21/9"]["AVIF"][100]
.path
)
assert path.exists()
Expand Down Expand Up @@ -175,7 +175,7 @@ class Meta:
def test_from_picture_field(self, stub_worker, image_upload_file):
luke = Profile.objects.create(name="Luke", picture=image_upload_file)
stub_worker.join()
path = luke.picture.aspect_ratios["16/9"]["WEBP"][100].path
path = luke.picture.aspect_ratios["16/9"]["AVIF"][100].path
assert path.exists()
migration = migrations.AlterPictureField("profile", "picture", PictureField())
migration.from_picture_field(Profile)
Expand Down Expand Up @@ -207,7 +207,7 @@ class Meta:
luke.refresh_from_db()
path = (
Profile.objects.get(pk=luke.pk)
.picture.aspect_ratios["16/9"]["WEBP"][100]
.picture.aspect_ratios["16/9"]["AVIF"][100]
.path
)
assert path.exists()
Expand Down Expand Up @@ -267,7 +267,7 @@ class Meta:
luke.refresh_from_db()
path = (
Profile.objects.get(pk=luke.pk)
.picture.aspect_ratios["16/9"]["WEBP"][100]
.picture.aspect_ratios["16/9"]["AVIF"][100]
.path
)
assert path.exists()
Expand Down
Loading