浏览代码

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>
zerolab 1 年之前
父节点
当前提交
96c3d719c2
共有 3 个文件被更改,包括 6 次插入5 次删除
  1. 3 2
      docs/topics/images.md
  2. 1 1
      wagtail/images/models.py
  3. 2 2
      wagtail/images/tests/test_image_operations.py

+ 3 - 2
docs/topics/images.md

@@ -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

+ 1 - 1
wagtail/images/models.py

@@ -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":

+ 2 - 2
wagtail/images/tests/test_image_operations.py

@@ -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",