From 30c1771d29eb8ca1e0626c41c60d9523ba75a729 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Tue, 4 Jan 2022 16:26:13 +0100 Subject: [PATCH] Thumbnail: Support for paletted PNG files --- src/pretix/helpers/thumb.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pretix/helpers/thumb.py b/src/pretix/helpers/thumb.py index 05e56554e..532c19b4d 100644 --- a/src/pretix/helpers/thumb.py +++ b/src/pretix/helpers/thumb.py @@ -173,7 +173,7 @@ def create_thumbnail(sourcename, size): image = resize_image(image, size) - if source.name.endswith('.jpg') or source.name.endswith('.jpeg'): + if source.name.lower().endswith('.jpg') or source.name.lower().endswith('.jpeg'): # Yields better file sizes for photos target_ext = 'jpeg' quality = 95 @@ -184,6 +184,8 @@ def create_thumbnail(sourcename, size): checksum = hashlib.md5(image.tobytes()).hexdigest() name = checksum + '.' + size.replace('^', 'c') + '.' + target_ext buffer = BytesIO() + if image.mode == "P" and source.name.lower().endswith('.png'): + image = image.convert('RGBA') if image.mode not in ("1", "L", "RGB", "RGBA"): image = image.convert('RGB') image.save(fp=buffer, format=target_ext.upper(), quality=quality)