Parcourir la source

Fix ico format conversion to work in template

Julie Rymer il y a 9 mois
Parent
commit
f5552c4044

+ 1 - 0
CHANGELOG.txt

@@ -18,6 +18,7 @@ Changelog
  * Fix: Support SVG icon id attributes with single quotes in the styleguide (Sage Abdullah)
  * Fix: Do not show delete button on model edit views if per-instance permissions prevent deletion (Matt Westcott)
  * Fix: Remove duplicate header in privacy dialog when a privacy setting is set on a parent page or collection (Matthias Brück)
+ * Fix: Allow renditions of `.ico` images (Julie Rymer)
  * Docs: Remove duplicate section on frontend caching proxies from performance page (Jake Howard)
  * Docs: Document `restriction_type` field on PageViewRestriction (Shlomo Markowitz)
  * Docs: Document Wagtail's bug bounty policy (Jake Howard)

+ 1 - 0
CONTRIBUTORS.md

@@ -818,6 +818,7 @@
 * Saksham Misra
 * Nigel van Keulen
 * Matthias Brück
+* Julie Rymer
 
 ## Translators
 

+ 1 - 0
docs/releases/6.2.md

@@ -32,6 +32,7 @@ depth: 1
  * Support SVG icon id attributes with single quotes in the styleguide (Sage Abdullah)
  * Do not show delete button on model edit views if per-instance permissions prevent deletion (Matt Westcott)
  * Remove duplicate header in privacy dialog when a privacy setting is set on a parent page or collection (Matthias Brück)
+ * Allow renditions of `.ico` images (Julie Rymer)
 
 
 ### Documentation

+ 2 - 1
docs/topics/images.md

@@ -449,7 +449,8 @@ You can encode the image into lossless AVIF or WebP format by using `format-avif
 You can save images as a `.ico` file using `format-ico`, which is especially useful when managing a site's favicon through the Admin.
 
 ```html+django
-<link rel="icon" href="{% image favicon_image format-ico %}" />
+{% image favicon_image format-ico as favicon_image_formatted %}
+<link rel="icon" type="image/x-icon" href="{{ favicon_image_formatted.url }}"/>
 ```
 
 (image_background_colour)=

+ 1 - 0
wagtail/images/models.py

@@ -59,6 +59,7 @@ IMAGE_FORMAT_EXTENSIONS = {
     "gif": ".gif",
     "webp": ".webp",
     "svg": ".svg",
+    "ico": ".ico",
 }
 
 

+ 12 - 0
wagtail/images/tests/test_image_operations.py

@@ -1,4 +1,5 @@
 from io import BytesIO
+from pathlib import Path
 from unittest.mock import patch
 
 from django.test import TestCase, override_settings
@@ -11,6 +12,7 @@ from wagtail.images.exceptions import (
 )
 from wagtail.images.image_operations import TransformOperation
 from wagtail.images.models import Filter, Image
+from wagtail.images.shortcuts import get_rendition_or_not_found
 from wagtail.images.tests.utils import (
     get_test_image_file,
     get_test_image_file_avif,
@@ -693,6 +695,16 @@ class TestFormatFilter(TestCase):
 
         self.assertEqual(out.format_name, "ico")
 
+    def test_ico_rendition(self):
+        fil = Filter(spec="width-400|format-ico")
+        good_image = Image.objects.create(
+            title="Test image",
+            file=get_test_image_file(),
+        )
+
+        rendition = get_rendition_or_not_found(good_image, fil)
+        self.assertEqual(Path(rendition.file.name).suffix, ".ico")
+
     def test_webp_lossless(self):
         fil = Filter(spec="width-400|format-webp-lossless")
         image = Image.objects.create(