Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: avoid to convert webp to jpeg #85

Merged
merged 6 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/85.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
avoid to convert webp to jpeg @mamico
mamico marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion plone/scale/scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def scaleImage(

else:
# All other formats only process a single frame
if format_ not in ("PNG", "GIF"):
if format_ not in ("PNG", "GIF", "WEBP"):
# Always generate JPEG, except if format is PNG or GIF.
mamico marked this conversation as resolved.
Show resolved Hide resolved
format_ = "JPEG"
image, format_ = scaleSingleFrame(
Expand Down
Binary file added plone/scale/tests/data/profile.webp
Binary file not shown.
11 changes: 11 additions & 0 deletions plone/scale/tests/test_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
CMYK = fio.read()
with open(os.path.join(TEST_DATA_LOCATION, "profile.jpg"), "rb") as fio:
PROFILE = fio.read()
with open(os.path.join(TEST_DATA_LOCATION, "profile.webp"), "rb") as fio:
PROFILE_WEBP = fio.read()
with open(os.path.join(TEST_DATA_LOCATION, "animated.gif"), "rb") as fio:
ANIGIF = fio.read()
with open(os.path.join(TEST_DATA_LOCATION, "animated2.gif"), "rb") as fio:
Expand Down Expand Up @@ -90,6 +92,15 @@ def testScaleWithFewColorsStaysColored(self):
self.assertEqual(image.mode, "RGB")
self.assertEqual(image.format, "JPEG")

def testScaledWeb(self):
mamico marked this conversation as resolved.
Show resolved Hide resolved
(imagedata, format, size) = scaleImage(PROFILE_WEBP, 120, 120)
self.assertEqual(format, "WEBP")
self.assertEqual(size, (120, 120))
self.assertTrue(len(imagedata) < len(PROFILE_WEBP))
input = StringIO(imagedata)
image = PIL.Image.open(input)
self.assertIsNotNone(image.info.get("icc_profile"))

def testAutomaticGreyscale(self):
src = PIL.Image.new("RGB", (256, 256), (255, 255, 255))
draw = PIL.ImageDraw.Draw(src)
Expand Down