summary refs log tree commit diff
path: root/synapse/rest/media
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2021-03-09 15:23:55 +0000
committerRichard van der Hoff <richard@matrix.org>2021-03-09 15:23:55 +0000
commit56c0c711c169548a2a4cf4e1948a76f7974ec4f8 (patch)
treeb8e625040829cea105d37556b11aa1598828e107 /synapse/rest/media
parentMerge remote-tracking branch 'origin/release-v1.29.0' into matrix-org-hotfixes (diff)
parentLink to the List user's media admin API from media Admin API docs (#9571) (diff)
downloadsynapse-56c0c711c169548a2a4cf4e1948a76f7974ec4f8.tar.xz
Merge remote-tracking branch 'origin/develop' into matrix-org-hotfixes
Diffstat (limited to 'synapse/rest/media')
-rw-r--r--synapse/rest/media/v1/thumbnailer.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/synapse/rest/media/v1/thumbnailer.py b/synapse/rest/media/v1/thumbnailer.py

index 07903e4017..988f52c78f 100644 --- a/synapse/rest/media/v1/thumbnailer.py +++ b/synapse/rest/media/v1/thumbnailer.py
@@ -96,9 +96,14 @@ class Thumbnailer: def _resize(self, width: int, height: int) -> Image: # 1-bit or 8-bit color palette images need converting to RGB # otherwise they will be scaled using nearest neighbour which - # looks awful - if self.image.mode in ["1", "P"]: - self.image = self.image.convert("RGB") + # looks awful. + # + # If the image has transparency, use RGBA instead. + if self.image.mode in ["1", "L", "P"]: + mode = "RGB" + if self.image.info.get("transparency", None) is not None: + mode = "RGBA" + self.image = self.image.convert(mode) return self.image.resize((width, height), Image.ANTIALIAS) def scale(self, width: int, height: int, output_type: str) -> BytesIO: