Просмотр исходного кода

Fix: Pillow error when uploading RGBA image (#3325) (#6241)

Signed-Off-By: Filip Štědronský <g@regnarg.cz>
Filip Štědronský 5 лет назад
Родитель
Сommit
81731c6e75
2 измененных файлов с 5 добавлено и 1 удалено
  1. 1 0
      changelog.d/6241.bugfix
  2. 4 1
      synapse/rest/media/v1/thumbnailer.py

+ 1 - 0
changelog.d/6241.bugfix

@@ -0,0 +1 @@
+Fix error from the Pillow library when uploading RGBA images.

+ 4 - 1
synapse/rest/media/v1/thumbnailer.py

@@ -129,5 +129,8 @@ class Thumbnailer(object):
 
     def _encode_image(self, output_image, output_type):
         output_bytes_io = BytesIO()
-        output_image.save(output_bytes_io, self.FORMATS[output_type], quality=80)
+        fmt = self.FORMATS[output_type]
+        if fmt == "JPEG":
+            output_image = output_image.convert("RGB")
+        output_image.save(output_bytes_io, fmt, quality=80)
         return output_bytes_io