From 1a9825e4839c6c55006b9fd336b34c1a3bb0d707 Mon Sep 17 00:00:00 2001 From: Martin Weinelt Date: Fri, 20 Sep 2024 13:05:27 +0200 Subject: [PATCH] Fix saving of non-RGB thumbnails as PNG The PNG format does not support non-RGB color spaces, which makes pillow raise an exception when trying to save e.g. a CMYK image in PNG format. Converting to RGB is recommended on the upstream issue, and as CMYK is a print format transparency does not need to be considered. Closes: #10741 --- synapse/media/thumbnailer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/media/thumbnailer.py b/synapse/media/thumbnailer.py index ee1118a53a..3845067835 100644 --- a/synapse/media/thumbnailer.py +++ b/synapse/media/thumbnailer.py @@ -206,7 +206,7 @@ def crop(self, width: int, height: int, output_type: str) -> BytesIO: def _encode_image(self, output_image: Image.Image, output_type: str) -> BytesIO: output_bytes_io = BytesIO() fmt = self.FORMATS[output_type] - if fmt == "JPEG": + if fmt == "JPEG" or fmt == "PNG" and output_image.mode == "CMYK": output_image = output_image.convert("RGB") output_image.save(output_bytes_io, fmt, quality=80) return output_bytes_io