Skip to content

Commit 1a9825e

Browse files
committed
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
1 parent 75e2c17 commit 1a9825e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

synapse/media/thumbnailer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def crop(self, width: int, height: int, output_type: str) -> BytesIO:
206206
def _encode_image(self, output_image: Image.Image, output_type: str) -> BytesIO:
207207
output_bytes_io = BytesIO()
208208
fmt = self.FORMATS[output_type]
209-
if fmt == "JPEG":
209+
if fmt == "JPEG" or fmt == "PNG" and output_image.mode == "CMYK":
210210
output_image = output_image.convert("RGB")
211211
output_image.save(output_bytes_io, fmt, quality=80)
212212
return output_bytes_io

0 commit comments

Comments
 (0)