Change the default WebP quality to 80

This is the value most used, and is the default in Willow too

Co-Authored-By: Aman Pandey <74553951+salty-ivy@users.noreply.github.com>
pull/10681/head
zerolab 2023-07-13 19:21:10 +01:00 zatwierdzone przez Thibaud Colas
rodzic ce4afcd578
commit 96c3d719c2
3 zmienionych plików z 6 dodań i 5 usunięć

Wyświetl plik

@ -371,12 +371,13 @@ representing the colour you would like to use:
## Image quality
Wagtail's JPEG and WebP image quality settings default to 85 (which is quite high). AVIF defaults to 80.
Wagtail's JPEG image quality settings default to 85 (which is quite high). AVIF and WebP default to 80.
This can be changed either globally or on a per-tag basis.
### Changing globally
Use the `WAGTAILIMAGES_AVIF_QUALITY`, `WAGTAILIMAGES_JPEG_QUALITY` and `WAGTAILIMAGES_WEBP_QUALITY` settings to change the global defaults of AVIF, JPEG and WebP quality:
Use the `WAGTAILIMAGES_AVIF_QUALITY`, `WAGTAILIMAGES_JPEG_QUALITY` and `WAGTAILIMAGES_WEBP_QUALITY` settings to change
the global defaults of AVIF, JPEG and WebP quality:
```python
# settings.py

Wyświetl plik

@ -964,7 +964,7 @@ class Filter:
elif "webp-quality" in env:
quality = env["webp-quality"]
else:
quality = getattr(settings, "WAGTAILIMAGES_WEBP_QUALITY", 85)
quality = getattr(settings, "WAGTAILIMAGES_WEBP_QUALITY", 80)
return willow.save_as_webp(output, quality=quality)
elif output_format == "avif":

Wyświetl plik

@ -878,7 +878,7 @@ class TestWebPQualityFilter(TestCase):
with patch("PIL.Image.Image.save") as save:
fil.run(image, f)
save.assert_called_with(f, "WEBP", quality=85, lossless=False)
save.assert_called_with(f, "WEBP", quality=80, lossless=False)
def test_webp_quality_filter(self):
fil = Filter(spec="width-400|webpquality-40|format-webp")
@ -893,7 +893,7 @@ class TestWebPQualityFilter(TestCase):
save.assert_called_with(f, "WEBP", quality=40, lossless=False)
def test_jpeg_quality_filter_invalid(self):
def test_webp_quality_filter_invalid(self):
fil = Filter(spec="width-400|webpquality-abc|format-webp")
image = Image.objects.create(
title="Test image",