From b62d4ab3bf8fa880e99727ce8708da4897cfedf8 Mon Sep 17 00:00:00 2001 From: tastytea Date: Thu, 27 Oct 2022 18:44:06 +0200 Subject: [PATCH] thumbnail WebP as WebP Closes: https://github.com/matrix-org/synapse/issues/11840 --- changelog.d/14890.bugfix | 1 + synapse/config/repository.py | 6 +++++- synapse/rest/media/v1/thumbnailer.py | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 changelog.d/14890.bugfix diff --git a/changelog.d/14890.bugfix b/changelog.d/14890.bugfix new file mode 100644 index 000000000000..fe21277a9ee5 --- /dev/null +++ b/changelog.d/14890.bugfix @@ -0,0 +1 @@ +Thumbnail WebP images as WebP instead of JPEG, preserving transparency. diff --git a/synapse/config/repository.py b/synapse/config/repository.py index e4759711ed95..6701aad7c58d 100644 --- a/synapse/config/repository.py +++ b/synapse/config/repository.py @@ -47,7 +47,7 @@ THUMBNAIL_SUPPORTED_MEDIA_FORMAT_MAP = { "image/jpeg": "jpeg", "image/jpg": "jpeg", - "image/webp": "jpeg", + "image/webp": "webp", # Thumbnails can only be jpeg or png. We choose png thumbnails for gif # because it can have transparency. "image/gif": "png", @@ -102,6 +102,10 @@ def parse_thumbnail_requirements( requirement.append( ThumbnailRequirement(width, height, method, "image/png") ) + elif thumbnail_format == "webp": + requirement.append( + ThumbnailRequirement(width, height, method, "image/webp") + ) else: raise Exception( "Unknown thumbnail mapping from %s to %s. This is a Synapse problem, please report!" diff --git a/synapse/rest/media/v1/thumbnailer.py b/synapse/rest/media/v1/thumbnailer.py index a48a4de92ae2..16654d6e3bd0 100644 --- a/synapse/rest/media/v1/thumbnailer.py +++ b/synapse/rest/media/v1/thumbnailer.py @@ -39,7 +39,7 @@ class ThumbnailError(Exception): class Thumbnailer: - FORMATS = {"image/jpeg": "JPEG", "image/png": "PNG"} + FORMATS = {"image/jpeg": "JPEG", "image/png": "PNG", "image/webp": "WEBP"} @staticmethod def set_limits(max_image_pixels: int) -> None: