kopia lustrzana https://github.com/wagtail/wagtail
Fix saving as .heic
rodzic
92567f6203
commit
15abe65eb4
|
@ -409,7 +409,7 @@ class WebPQualityOperation(FilterOperation):
|
||||||
|
|
||||||
|
|
||||||
class FormatOperation(FilterOperation):
|
class FormatOperation(FilterOperation):
|
||||||
supported_formats = ["jpeg", "png", "gif", "webp", "avif", "ico"]
|
supported_formats = ["jpeg", "png", "gif", "webp", "avif", "ico", "heic"]
|
||||||
|
|
||||||
def construct(self, format, *options):
|
def construct(self, format, *options):
|
||||||
self.format = format
|
self.format = format
|
||||||
|
|
|
@ -1071,12 +1071,12 @@ class Filter:
|
||||||
"output-format-options" in env
|
"output-format-options" in env
|
||||||
and "lossless" in env["output-format-options"]
|
and "lossless" in env["output-format-options"]
|
||||||
):
|
):
|
||||||
return willow.save_as_heif(output, lossless=True)
|
return willow.save_as_heic(output, lossless=True)
|
||||||
elif "heic-quality" in env:
|
elif "heic-quality" in env:
|
||||||
quality = env["heic-quality"]
|
quality = env["heic-quality"]
|
||||||
else:
|
else:
|
||||||
quality = getattr(settings, "WAGTAILIMAGES_HEIC_QUALITY", 80)
|
quality = getattr(settings, "WAGTAILIMAGES_HEIC_QUALITY", 80)
|
||||||
return willow.save_as_heif(output, quality=quality)
|
return willow.save_as_heic(output, quality=quality)
|
||||||
elif output_format == "svg":
|
elif output_format == "svg":
|
||||||
return willow.save_as_svg(output)
|
return willow.save_as_svg(output)
|
||||||
elif output_format == "ico":
|
elif output_format == "ico":
|
||||||
|
|
|
@ -719,6 +719,29 @@ class TestFormatFilter(TestCase):
|
||||||
# quality=80 is default for the Willow and PIL libraries
|
# quality=80 is default for the Willow and PIL libraries
|
||||||
save.assert_called_with(f, "WEBP", quality=80, lossless=True)
|
save.assert_called_with(f, "WEBP", quality=80, lossless=True)
|
||||||
|
|
||||||
|
def test_heic(self):
|
||||||
|
fil = Filter(spec="width-400|format-heic")
|
||||||
|
image = Image.objects.create(
|
||||||
|
title="Test image",
|
||||||
|
file=get_test_image_file(),
|
||||||
|
)
|
||||||
|
out = fil.run(image, BytesIO())
|
||||||
|
|
||||||
|
self.assertEqual(out.format_name, "heic")
|
||||||
|
|
||||||
|
def test_heic_lossless(self):
|
||||||
|
fil = Filter(spec="width-400|format-heic-lossless")
|
||||||
|
image = Image.objects.create(
|
||||||
|
title="Test image",
|
||||||
|
file=get_test_image_file(),
|
||||||
|
)
|
||||||
|
|
||||||
|
f = BytesIO()
|
||||||
|
with patch("PIL.Image.Image.save") as save:
|
||||||
|
fil.run(image, f)
|
||||||
|
|
||||||
|
save.assert_called_with(f, "HEIF", quality=-1, chroma=444)
|
||||||
|
|
||||||
def test_invalid(self):
|
def test_invalid(self):
|
||||||
fil = Filter(spec="width-400|format-foo")
|
fil = Filter(spec="width-400|format-foo")
|
||||||
image = Image.objects.create(
|
image = Image.objects.create(
|
||||||
|
|
Ładowanie…
Reference in New Issue