diff --git a/README.md b/README.md index cee30cb..9118c98 100644 --- a/README.md +++ b/README.md @@ -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", @@ -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. @@ -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 diff --git a/pictures/conf.py b/pictures/conf.py index 88f8a8b..1e7c7ac 100644 --- a/pictures/conf.py +++ b/pictures/conf.py @@ -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", diff --git a/pyproject.toml b/pyproject.toml index c9c3467..ef3ca07 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 = [ diff --git a/tests/contrib/test_cleanup.py b/tests/contrib/test_cleanup.py index f38986d..525c8a3 100644 --- a/tests/contrib/test_cleanup.py +++ b/tests/contrib/test_cleanup.py @@ -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)): diff --git a/tests/contrib/test_rest_framework.py b/tests/contrib/test_rest_framework.py index f0f178a..c0aff71 100644 --- a/tests/contrib/test_rest_framework.py +++ b/tests/contrib/test_rest_framework.py @@ -13,7 +13,7 @@ class ProfileSerializer(serializers.ModelSerializer): image = rest_framework.PictureField(source="picture") image_mobile = rest_framework.PictureField( - source="picture", aspect_ratios=["3/2"], file_types=["WEBP"] + source="picture", aspect_ratios=["3/2"], file_types=["AVIF"] ) class Meta: @@ -74,60 +74,60 @@ def test_to_representation(self, image_upload_file, settings): "ratios": { "null": { "sources": { - "image/webp": { - "800": "/media/testapp/profile/image/800w.webp", - "100": "/media/testapp/profile/image/100w.webp", - "200": "/media/testapp/profile/image/200w.webp", - "300": "/media/testapp/profile/image/300w.webp", - "400": "/media/testapp/profile/image/400w.webp", - "500": "/media/testapp/profile/image/500w.webp", - "600": "/media/testapp/profile/image/600w.webp", - "700": "/media/testapp/profile/image/700w.webp", + "image/avif": { + "800": "/media/testapp/profile/image/800w.avif", + "100": "/media/testapp/profile/image/100w.avif", + "200": "/media/testapp/profile/image/200w.avif", + "300": "/media/testapp/profile/image/300w.avif", + "400": "/media/testapp/profile/image/400w.avif", + "500": "/media/testapp/profile/image/500w.avif", + "600": "/media/testapp/profile/image/600w.avif", + "700": "/media/testapp/profile/image/700w.avif", } }, "media": "(min-width: 0px) and (max-width: 1199px) 100vw, 1200px", }, "1/1": { "sources": { - "image/webp": { - "800": "/media/testapp/profile/image/1/800w.webp", - "100": "/media/testapp/profile/image/1/100w.webp", - "200": "/media/testapp/profile/image/1/200w.webp", - "300": "/media/testapp/profile/image/1/300w.webp", - "400": "/media/testapp/profile/image/1/400w.webp", - "500": "/media/testapp/profile/image/1/500w.webp", - "600": "/media/testapp/profile/image/1/600w.webp", - "700": "/media/testapp/profile/image/1/700w.webp", + "image/avif": { + "800": "/media/testapp/profile/image/1/800w.avif", + "100": "/media/testapp/profile/image/1/100w.avif", + "200": "/media/testapp/profile/image/1/200w.avif", + "300": "/media/testapp/profile/image/1/300w.avif", + "400": "/media/testapp/profile/image/1/400w.avif", + "500": "/media/testapp/profile/image/1/500w.avif", + "600": "/media/testapp/profile/image/1/600w.avif", + "700": "/media/testapp/profile/image/1/700w.avif", } }, "media": "(min-width: 0px) and (max-width: 1199px) 100vw, 1200px", }, "3/2": { "sources": { - "image/webp": { - "800": "/media/testapp/profile/image/3_2/800w.webp", - "100": "/media/testapp/profile/image/3_2/100w.webp", - "200": "/media/testapp/profile/image/3_2/200w.webp", - "300": "/media/testapp/profile/image/3_2/300w.webp", - "400": "/media/testapp/profile/image/3_2/400w.webp", - "500": "/media/testapp/profile/image/3_2/500w.webp", - "600": "/media/testapp/profile/image/3_2/600w.webp", - "700": "/media/testapp/profile/image/3_2/700w.webp", + "image/avif": { + "800": "/media/testapp/profile/image/3_2/800w.avif", + "100": "/media/testapp/profile/image/3_2/100w.avif", + "200": "/media/testapp/profile/image/3_2/200w.avif", + "300": "/media/testapp/profile/image/3_2/300w.avif", + "400": "/media/testapp/profile/image/3_2/400w.avif", + "500": "/media/testapp/profile/image/3_2/500w.avif", + "600": "/media/testapp/profile/image/3_2/600w.avif", + "700": "/media/testapp/profile/image/3_2/700w.avif", } }, "media": "(min-width: 0px) and (max-width: 1199px) 100vw, 1200px", }, "16/9": { "sources": { - "image/webp": { - "800": "/media/testapp/profile/image/16_9/800w.webp", - "100": "/media/testapp/profile/image/16_9/100w.webp", - "200": "/media/testapp/profile/image/16_9/200w.webp", - "300": "/media/testapp/profile/image/16_9/300w.webp", - "400": "/media/testapp/profile/image/16_9/400w.webp", - "500": "/media/testapp/profile/image/16_9/500w.webp", - "600": "/media/testapp/profile/image/16_9/600w.webp", - "700": "/media/testapp/profile/image/16_9/700w.webp", + "image/avif": { + "800": "/media/testapp/profile/image/16_9/800w.avif", + "100": "/media/testapp/profile/image/16_9/100w.avif", + "200": "/media/testapp/profile/image/16_9/200w.avif", + "300": "/media/testapp/profile/image/16_9/300w.avif", + "400": "/media/testapp/profile/image/16_9/400w.avif", + "500": "/media/testapp/profile/image/16_9/500w.avif", + "600": "/media/testapp/profile/image/16_9/600w.avif", + "700": "/media/testapp/profile/image/16_9/700w.avif", } }, "media": "(min-width: 0px) and (max-width: 1199px) 100vw, 1200px", @@ -156,15 +156,15 @@ def test_to_representation__with_aspect_ratios( "ratios": { "1/1": { "sources": { - "image/webp": { - "800": "/media/testapp/profile/image/1/800w.webp", - "100": "/media/testapp/profile/image/1/100w.webp", - "200": "/media/testapp/profile/image/1/200w.webp", - "300": "/media/testapp/profile/image/1/300w.webp", - "400": "/media/testapp/profile/image/1/400w.webp", - "500": "/media/testapp/profile/image/1/500w.webp", - "600": "/media/testapp/profile/image/1/600w.webp", - "700": "/media/testapp/profile/image/1/700w.webp", + "image/avif": { + "800": "/media/testapp/profile/image/1/800w.avif", + "100": "/media/testapp/profile/image/1/100w.avif", + "200": "/media/testapp/profile/image/1/200w.avif", + "300": "/media/testapp/profile/image/1/300w.avif", + "400": "/media/testapp/profile/image/1/400w.avif", + "500": "/media/testapp/profile/image/1/500w.avif", + "600": "/media/testapp/profile/image/1/600w.avif", + "700": "/media/testapp/profile/image/1/700w.avif", } }, "media": "(min-width: 0px) and (max-width: 991px) 100vw, (min-width: 992px) and (max-width: 1199px) 25vw, 400px", @@ -221,15 +221,15 @@ def test_to_representation__no_get_params(self, rf, image_upload_file, settings) "ratios": { "3/2": { "sources": { - "image/webp": { - "800": "/media/testapp/profile/image/3_2/800w.webp", - "100": "/media/testapp/profile/image/3_2/100w.webp", - "200": "/media/testapp/profile/image/3_2/200w.webp", - "300": "/media/testapp/profile/image/3_2/300w.webp", - "400": "/media/testapp/profile/image/3_2/400w.webp", - "500": "/media/testapp/profile/image/3_2/500w.webp", - "600": "/media/testapp/profile/image/3_2/600w.webp", - "700": "/media/testapp/profile/image/3_2/700w.webp", + "image/avif": { + "800": "/media/testapp/profile/image/3_2/800w.avif", + "100": "/media/testapp/profile/image/3_2/100w.avif", + "200": "/media/testapp/profile/image/3_2/200w.avif", + "300": "/media/testapp/profile/image/3_2/300w.avif", + "400": "/media/testapp/profile/image/3_2/400w.avif", + "500": "/media/testapp/profile/image/3_2/500w.avif", + "600": "/media/testapp/profile/image/3_2/600w.avif", + "700": "/media/testapp/profile/image/3_2/700w.avif", } }, "media": "(min-width: 0px) and (max-width: 1199px) 100vw, 1200px", @@ -254,30 +254,30 @@ def test_to_representation__multiple_ratios(self, rf, image_upload_file, setting "ratios": { "3/2": { "sources": { - "image/webp": { - "800": "/media/testapp/profile/image/3_2/800w.webp", - "100": "/media/testapp/profile/image/3_2/100w.webp", - "200": "/media/testapp/profile/image/3_2/200w.webp", - "300": "/media/testapp/profile/image/3_2/300w.webp", - "400": "/media/testapp/profile/image/3_2/400w.webp", - "500": "/media/testapp/profile/image/3_2/500w.webp", - "600": "/media/testapp/profile/image/3_2/600w.webp", - "700": "/media/testapp/profile/image/3_2/700w.webp", + "image/avif": { + "800": "/media/testapp/profile/image/3_2/800w.avif", + "100": "/media/testapp/profile/image/3_2/100w.avif", + "200": "/media/testapp/profile/image/3_2/200w.avif", + "300": "/media/testapp/profile/image/3_2/300w.avif", + "400": "/media/testapp/profile/image/3_2/400w.avif", + "500": "/media/testapp/profile/image/3_2/500w.avif", + "600": "/media/testapp/profile/image/3_2/600w.avif", + "700": "/media/testapp/profile/image/3_2/700w.avif", } }, "media": "(min-width: 0px) and (max-width: 1199px) 100vw, 1200px", }, "16/9": { "sources": { - "image/webp": { - "800": "/media/testapp/profile/image/16_9/800w.webp", - "100": "/media/testapp/profile/image/16_9/100w.webp", - "200": "/media/testapp/profile/image/16_9/200w.webp", - "300": "/media/testapp/profile/image/16_9/300w.webp", - "400": "/media/testapp/profile/image/16_9/400w.webp", - "500": "/media/testapp/profile/image/16_9/500w.webp", - "600": "/media/testapp/profile/image/16_9/600w.webp", - "700": "/media/testapp/profile/image/16_9/700w.webp", + "image/avif": { + "800": "/media/testapp/profile/image/16_9/800w.avif", + "100": "/media/testapp/profile/image/16_9/100w.avif", + "200": "/media/testapp/profile/image/16_9/200w.avif", + "300": "/media/testapp/profile/image/16_9/300w.avif", + "400": "/media/testapp/profile/image/16_9/400w.avif", + "500": "/media/testapp/profile/image/16_9/500w.avif", + "600": "/media/testapp/profile/image/16_9/600w.avif", + "700": "/media/testapp/profile/image/16_9/700w.avif", } }, "media": "(min-width: 0px) and (max-width: 1199px) 100vw, 1200px", @@ -302,15 +302,15 @@ def test_to_representation__with_container(self, rf, image_upload_file, settings "ratios": { "16/9": { "sources": { - "image/webp": { - "800": "/media/testapp/profile/image/16_9/800w.webp", - "100": "/media/testapp/profile/image/16_9/100w.webp", - "200": "/media/testapp/profile/image/16_9/200w.webp", - "300": "/media/testapp/profile/image/16_9/300w.webp", - "400": "/media/testapp/profile/image/16_9/400w.webp", - "500": "/media/testapp/profile/image/16_9/500w.webp", - "600": "/media/testapp/profile/image/16_9/600w.webp", - "700": "/media/testapp/profile/image/16_9/700w.webp", + "image/avif": { + "800": "/media/testapp/profile/image/16_9/800w.avif", + "100": "/media/testapp/profile/image/16_9/100w.avif", + "200": "/media/testapp/profile/image/16_9/200w.avif", + "300": "/media/testapp/profile/image/16_9/300w.avif", + "400": "/media/testapp/profile/image/16_9/400w.avif", + "500": "/media/testapp/profile/image/16_9/500w.avif", + "600": "/media/testapp/profile/image/16_9/600w.avif", + "700": "/media/testapp/profile/image/16_9/700w.avif", } }, "media": "(min-width: 0px) and (max-width: 1199px) 100vw, 1200px", @@ -336,15 +336,15 @@ def test_to_representation__without_container( "ratios": { "16/9": { "sources": { - "image/webp": { - "800": "/media/testapp/profile/image/16_9/800w.webp", - "100": "/media/testapp/profile/image/16_9/100w.webp", - "200": "/media/testapp/profile/image/16_9/200w.webp", - "300": "/media/testapp/profile/image/16_9/300w.webp", - "400": "/media/testapp/profile/image/16_9/400w.webp", - "500": "/media/testapp/profile/image/16_9/500w.webp", - "600": "/media/testapp/profile/image/16_9/600w.webp", - "700": "/media/testapp/profile/image/16_9/700w.webp", + "image/avif": { + "800": "/media/testapp/profile/image/16_9/800w.avif", + "100": "/media/testapp/profile/image/16_9/100w.avif", + "200": "/media/testapp/profile/image/16_9/200w.avif", + "300": "/media/testapp/profile/image/16_9/300w.avif", + "400": "/media/testapp/profile/image/16_9/400w.avif", + "500": "/media/testapp/profile/image/16_9/500w.avif", + "600": "/media/testapp/profile/image/16_9/600w.avif", + "700": "/media/testapp/profile/image/16_9/700w.avif", } }, "media": "(min-width: 0px) and (max-width: 1199px) 100vw, 1200px", @@ -384,15 +384,15 @@ def test_to_representation__with_prefiltered_aspect_ratio_and_source( "ratios": { "3/2": { "sources": { - "image/webp": { - "800": "/media/testapp/profile/image/3_2/800w.webp", - "100": "/media/testapp/profile/image/3_2/100w.webp", - "200": "/media/testapp/profile/image/3_2/200w.webp", - "300": "/media/testapp/profile/image/3_2/300w.webp", - "400": "/media/testapp/profile/image/3_2/400w.webp", - "500": "/media/testapp/profile/image/3_2/500w.webp", - "600": "/media/testapp/profile/image/3_2/600w.webp", - "700": "/media/testapp/profile/image/3_2/700w.webp", + "image/avif": { + "800": "/media/testapp/profile/image/3_2/800w.avif", + "100": "/media/testapp/profile/image/3_2/100w.avif", + "200": "/media/testapp/profile/image/3_2/200w.avif", + "300": "/media/testapp/profile/image/3_2/300w.avif", + "400": "/media/testapp/profile/image/3_2/400w.avif", + "500": "/media/testapp/profile/image/3_2/500w.avif", + "600": "/media/testapp/profile/image/3_2/600w.avif", + "700": "/media/testapp/profile/image/3_2/700w.avif", } }, "media": "(min-width: 0px) and (max-width: 1199px) 100vw, 1200px", diff --git a/tests/test_migrations.py b/tests/test_migrations.py index 00f509e..acf7f30 100644 --- a/tests/test_migrations.py +++ b/tests/test_migrations.py @@ -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) @@ -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() @@ -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) @@ -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() @@ -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() diff --git a/tests/test_models.py b/tests/test_models.py index 2aa329a..b745158 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -27,7 +27,7 @@ def override_field_aspect_ratios(field, aspect_ratios): class TestPillowPicture: picture_with_ratio = PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction("4/3"), storage=default_storage, width=800, @@ -35,7 +35,7 @@ class TestPillowPicture: picture_without_ratio = PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=None, storage=default_storage, width=800, @@ -54,12 +54,12 @@ def test_url(self, settings): settings.PICTURES["USE_PLACEHOLDERS"] = False assert ( self.picture_with_ratio.url - == "/media/testapp/simplemodel/image/4_3/800w.webp" + == "/media/testapp/simplemodel/image/4_3/800w.avif" ) def test_url__placeholder(self, settings): settings.PICTURES["USE_PLACEHOLDERS"] = True - assert self.picture_with_ratio.url == "/_pictures/image/4x3/800w.WEBP" + assert self.picture_with_ratio.url == "/_pictures/image/4x3/800w.AVIF" def test_height(self): assert self.picture_with_ratio.height == 600 @@ -67,10 +67,10 @@ def test_height(self): def test_name(self): assert Path(self.picture_without_ratio.name) == Path( - "testapp/simplemodel/image/800w.webp" + "testapp/simplemodel/image/800w.avif" ) assert Path(self.picture_with_ratio.name) == Path( - "testapp/simplemodel/image/4_3/800w.webp" + "testapp/simplemodel/image/4_3/800w.avif" ) def test_path(self): @@ -92,7 +92,7 @@ def test_process__copy(self): image = Image.new("RGB", (800, 800), (255, 55, 255)) assert PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=None, storage=default_storage, width=100, @@ -102,7 +102,7 @@ def test_process__copy(self): assert PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio="4/3", storage=default_storage, width=400, @@ -124,168 +124,168 @@ def test_symmetric_difference(self, image_upload_file): { PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(3, 2), storage=default_storage, width=300, ), PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=None, storage=default_storage, width=600, ), PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(3, 2), storage=default_storage, width=500, ), PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(16, 9), storage=default_storage, width=500, ), PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=None, storage=default_storage, width=300, ), PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(3, 2), storage=default_storage, width=700, ), PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(3, 2), storage=default_storage, width=800, ), PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(16, 9), storage=default_storage, width=200, ), PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(16, 9), storage=default_storage, width=300, ), PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(16, 9), storage=default_storage, width=700, ), PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=None, storage=default_storage, width=100, ), PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(3, 2), storage=default_storage, width=400, ), PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=None, storage=default_storage, width=800, ), PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(3, 2), storage=default_storage, width=100, ), PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=None, storage=default_storage, width=700, ), PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=None, storage=default_storage, width=200, ), PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(3, 2), storage=default_storage, width=600, ), PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=None, storage=default_storage, width=500, ), PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(16, 9), storage=default_storage, width=800, ), PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(3, 2), storage=default_storage, width=200, ), PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(16, 9), storage=default_storage, width=100, ), PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(16, 9), storage=default_storage, width=400, ), PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(16, 9), storage=default_storage, width=600, ), PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=None, storage=default_storage, width=400, @@ -294,224 +294,224 @@ def test_symmetric_difference(self, image_upload_file): { PillowPicture( parent_name="testapp/profile/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(1, 1), storage=default_storage, width=600, ), PillowPicture( parent_name="testapp/profile/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(3, 2), storage=default_storage, width=300, ), PillowPicture( parent_name="testapp/profile/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(1, 1), storage=default_storage, width=800, ), PillowPicture( parent_name="testapp/profile/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=None, storage=default_storage, width=500, ), PillowPicture( parent_name="testapp/profile/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=None, storage=default_storage, width=700, ), PillowPicture( parent_name="testapp/profile/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=None, storage=default_storage, width=100, ), PillowPicture( parent_name="testapp/profile/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(16, 9), storage=default_storage, width=500, ), PillowPicture( parent_name="testapp/profile/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(16, 9), storage=default_storage, width=700, ), PillowPicture( parent_name="testapp/profile/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=None, storage=default_storage, width=800, ), PillowPicture( parent_name="testapp/profile/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(1, 1), storage=default_storage, width=200, ), PillowPicture( parent_name="testapp/profile/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(16, 9), storage=default_storage, width=100, ), PillowPicture( parent_name="testapp/profile/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=None, storage=default_storage, width=600, ), PillowPicture( parent_name="testapp/profile/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(1, 1), storage=default_storage, width=100, ), PillowPicture( parent_name="testapp/profile/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(1, 1), storage=default_storage, width=700, ), PillowPicture( parent_name="testapp/profile/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(3, 2), storage=default_storage, width=800, ), PillowPicture( parent_name="testapp/profile/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=None, storage=default_storage, width=200, ), PillowPicture( parent_name="testapp/profile/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(3, 2), storage=default_storage, width=500, ), PillowPicture( parent_name="testapp/profile/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(16, 9), storage=default_storage, width=800, ), PillowPicture( parent_name="testapp/profile/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(16, 9), storage=default_storage, width=300, ), PillowPicture( parent_name="testapp/profile/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(1, 1), storage=default_storage, width=300, ), PillowPicture( parent_name="testapp/profile/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(16, 9), storage=default_storage, width=600, ), PillowPicture( parent_name="testapp/profile/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(3, 2), storage=default_storage, width=700, ), PillowPicture( parent_name="testapp/profile/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(1, 1), storage=default_storage, width=400, ), PillowPicture( parent_name="testapp/profile/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(16, 9), storage=default_storage, width=400, ), PillowPicture( parent_name="testapp/profile/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(3, 2), storage=default_storage, width=400, ), PillowPicture( parent_name="testapp/profile/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(3, 2), storage=default_storage, width=200, ), PillowPicture( parent_name="testapp/profile/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=None, storage=default_storage, width=300, ), PillowPicture( parent_name="testapp/profile/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(3, 2), storage=default_storage, width=600, ), PillowPicture( parent_name="testapp/profile/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(3, 2), storage=default_storage, width=100, ), PillowPicture( parent_name="testapp/profile/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(16, 9), storage=default_storage, width=200, ), PillowPicture( parent_name="testapp/profile/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=None, storage=default_storage, width=400, ), PillowPicture( parent_name="testapp/profile/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(1, 1), storage=default_storage, width=500, @@ -526,7 +526,7 @@ def test_save(self, stub_worker, image_upload_file): stub_worker.join() assert default_storage.exists(obj.picture.name) - assert obj.picture.aspect_ratios["16/9"]["WEBP"][100].path.exists() + assert obj.picture.aspect_ratios["16/9"]["AVIF"][100].path.exists() @pytest.mark.django_db def test_save_JPEG_RGA(self, stub_worker, image_upload_file): @@ -554,13 +554,13 @@ def test_exif_transpose(self, stub_worker): stub_worker.join() assert default_storage.exists(obj.picture.name) - assert obj.picture.aspect_ratios["16/9"]["WEBP"][100].path.exists() + assert obj.picture.aspect_ratios["16/9"]["AVIF"][100].path.exists() with Image.open( - obj.picture.aspect_ratios["16/9"]["WEBP"][100].path + obj.picture.aspect_ratios["16/9"]["AVIF"][100].path ) as img_small: assert img_small.size == (100, 56) pixels = img_small.load() - assert pixels[0, 0] == (2, 0, 255) # blue is on the top, always blue! + assert pixels[0, 0][1] == 0 # blue is on the top, always blue! @pytest.mark.django_db def test_save__is_blank(self, monkeypatch): @@ -577,7 +577,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() @@ -593,7 +593,7 @@ def test_update_all(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() @@ -602,7 +602,7 @@ def test_update_all(self, stub_worker, image_upload_file): obj.picture.update_all(old) stub_worker.join() assert default_storage.exists(name) - assert obj.picture.aspect_ratios["1/1"]["WEBP"][100].path.exists() + assert obj.picture.aspect_ratios["1/1"]["AVIF"][100].path.exists() assert not path.exists() @pytest.mark.django_db @@ -639,59 +639,59 @@ def test_integration(self, image_upload_file): obj = SimpleModel.objects.create(picture=image_upload_file) assert obj.picture.aspect_ratios == { None: { - "WEBP": { + "AVIF": { 800: PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=None, storage=default_storage, width=800, ), 100: PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=None, storage=default_storage, width=100, ), 200: PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=None, storage=default_storage, width=200, ), 300: PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=None, storage=default_storage, width=300, ), 400: PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=None, storage=default_storage, width=400, ), 500: PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=None, storage=default_storage, width=500, ), 600: PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=None, storage=default_storage, width=600, ), 700: PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=None, storage=default_storage, width=700, @@ -699,59 +699,59 @@ def test_integration(self, image_upload_file): } }, "3/2": { - "WEBP": { + "AVIF": { 800: PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(3, 2), storage=default_storage, width=800, ), 100: PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(3, 2), storage=default_storage, width=100, ), 200: PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(3, 2), storage=default_storage, width=200, ), 300: PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(3, 2), storage=default_storage, width=300, ), 400: PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(3, 2), storage=default_storage, width=400, ), 500: PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(3, 2), storage=default_storage, width=500, ), 600: PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(3, 2), storage=default_storage, width=600, ), 700: PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(3, 2), storage=default_storage, width=700, @@ -759,59 +759,59 @@ def test_integration(self, image_upload_file): } }, "16/9": { - "WEBP": { + "AVIF": { 800: PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(16, 9), storage=default_storage, width=800, ), 100: PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(16, 9), storage=default_storage, width=100, ), 200: PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(16, 9), storage=default_storage, width=200, ), 300: PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(16, 9), storage=default_storage, width=300, ), 400: PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(16, 9), storage=default_storage, width=400, ), 500: PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(16, 9), storage=default_storage, width=500, ), 600: PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(16, 9), storage=default_storage, width=600, ), 700: PillowPicture( parent_name="testapp/simplemodel/image.png", - file_type="WEBP", + file_type="AVIF", aspect_ratio=Fraction(16, 9), storage=default_storage, width=700, diff --git a/tests/test_templatetags.py b/tests/test_templatetags.py index 270e20b..0f54dfb 100644 --- a/tests/test_templatetags.py +++ b/tests/test_templatetags.py @@ -5,8 +5,8 @@ picture_html = b""" - Spiderman @@ -14,8 +14,8 @@ picture_html_large = b""" - Spiderman @@ -23,8 +23,8 @@ picture_with_placeholders_html = b""" - Spiderman @@ -48,6 +48,7 @@ def test_picture__large(client, large_image_upload_file, settings): profile = Profile.objects.create(name="Spiderman", picture=large_image_upload_file) response = client.get(profile.get_absolute_url()) assert response.status_code == 200 + print(response.content.decode()) assert picture_html_large in response.content @@ -67,7 +68,7 @@ def test_picture__placeholder_with_alt(client, image_upload_file, settings): html = picture( profile.picture, img_alt="Event 2022/2023", ratio="3/2", img_loading="lazy" ) - assert "/_pictures/Event%25202022%252F2023/3x2/800w.WEBP" in html + assert "/_pictures/Event%25202022%252F2023/3x2/800w.AVIF" in html @pytest.mark.django_db @@ -122,8 +123,8 @@ def test_picture__field_defaults(image_upload_file): def test_img_url(image_upload_file): profile = Profile.objects.create(name="Spiderman", picture=image_upload_file) assert ( - img_url(profile.picture, ratio="3/2", file_type="webp", width="800") - == "/_pictures/image/3x2/800w.WEBP" + img_url(profile.picture, ratio="3/2", file_type="avif", width="800") + == "/_pictures/image/3x2/800w.AVIF" ) @@ -131,7 +132,7 @@ def test_img_url(image_upload_file): def test_img_url__raise_wrong_ratio(image_upload_file): profile = Profile.objects.create(name="Spiderman", picture=image_upload_file) with pytest.raises(ValueError) as e: - img_url(profile.picture, ratio="2/3", file_type="webp", width=800) + img_url(profile.picture, ratio="2/3", file_type="avif", width=800) assert "Invalid ratio: 2/3. Choices are: 1/1, 3/2, 16/9" in str(e.value) @@ -140,7 +141,7 @@ def test_img_url__raise_wrong_file_type(image_upload_file): profile = Profile.objects.create(name="Spiderman", picture=image_upload_file) with pytest.raises(ValueError) as e: img_url(profile.picture, ratio="3/2", file_type="gif", width=800) - assert "Invalid file type: gif. Choices are: WEBP" in str(e.value) + assert "Invalid file type: gif. Choices are: AVIF" in str(e.value) @pytest.mark.django_db @@ -148,7 +149,7 @@ def test_img_url__too_small(tiny_image_upload_file, caplog): profile = Profile.objects.create(name="Spiderman", picture=tiny_image_upload_file) with pytest.warns() as record: assert ( - img_url(profile.picture, ratio="3/2", file_type="webp", width="800") + img_url(profile.picture, ratio="3/2", file_type="avif", width="800") == "/media/testapp/profile/image.png" ) assert len(record) == 1 diff --git a/tests/test_views.py b/tests/test_views.py index 0b7b56c..52c7d9a 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -5,15 +5,15 @@ def test_placeholder(rf): - response = placeholder(rf.get("/"), 400, "4x3", "webp", "amazing_img") + response = placeholder(rf.get("/"), 400, "4x3", "avif", "amazing_img") assert response.status_code == 200 - assert response["Content-Type"] == "image/webp" + assert response["Content-Type"] == "image/avif" assert response["Cache-Control"] == "public, max-age=31536000" def test_placeholder__invalid_ratio(rf): with pytest.raises(Http404): - placeholder(rf.get("/"), 400, "not-a-fraction", "webp", "amazing_img") + placeholder(rf.get("/"), 400, "not-a-fraction", "avif", "amazing_img") def test_placeholder__invalid_file_type(rf):