From 60aebdb27edfe00f43b7e95bc60a730408bc3084 Mon Sep 17 00:00:00 2001 From: Martin Weinelt Date: Tue, 8 Oct 2024 19:32:25 +0200 Subject: [PATCH] Fix saving of non-RGB thumbnails as PNG (#17736) --- changelog.d/17736.bugfix | 1 + synapse/media/thumbnailer.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 changelog.d/17736.bugfix diff --git a/changelog.d/17736.bugfix b/changelog.d/17736.bugfix new file mode 100644 index 00000000000..0d3fd06962c --- /dev/null +++ b/changelog.d/17736.bugfix @@ -0,0 +1 @@ +Fix saving of PNG thumbnails, when the original image is in the CMYK color space. diff --git a/synapse/media/thumbnailer.py b/synapse/media/thumbnailer.py index ee1118a53a2..3845067835a 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