Skip feature detection if image is an SVG

Fixes https://github.com/wagtail/wagtail/issues/11172
pull/11234/head
Joshua Munn 2023-11-12 17:28:08 +00:00 zatwierdzone przez Matt Westcott
rodzic 1a4595b60b
commit c36cf20dd4
2 zmienionych plików z 23 dodań i 1 usunięć
wagtail/images

Wyświetl plik

@ -377,6 +377,11 @@ class AbstractImage(ImageFileMixin, CollectionMember, index.Indexed, models.Mode
self.focal_point_height = None
def get_suggested_focal_point(self):
if self.is_svg():
# We can't run feature detection on SVGs, and don't provide a
# pathway from SVG -> raster formats, so don't try it.
return None
with self.get_willow_image() as willow:
faces = willow.detect_faces()

Wyświetl plik

@ -28,7 +28,12 @@ from wagtail.test.testapp.models import (
)
from wagtail.test.utils import WagtailTestUtils, override_settings
from .utils import Image, get_test_image_file, get_test_image_filename
from .utils import (
Image,
get_test_image_file,
get_test_image_file_svg,
get_test_image_filename,
)
class CustomStorage(Storage):
@ -123,6 +128,18 @@ class TestImage(TestCase):
self.image.get_file_hash(), "4dd0211870e130b7e1690d2ec53c499a54a48fef"
)
def test_get_suggested_focal_point_svg(self):
"""
Feature detection should not be run on SVGs.
https://github.com/wagtail/wagtail/issues/11172
"""
image = Image.objects.create(
title="Test SVG",
file=get_test_image_file_svg(),
)
self.assertIsNone(image.get_suggested_focal_point())
class TestImageQuerySet(TransactionTestCase):
fixtures = ["test_empty.json"]