From d2f795b87d94e3c38abf65d5558edede13bd0799 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 Signed-off-by: Ronny (tastytea) Gutbrod --- changelog.d/14890.bugfix | 1 + synapse/config/repository.py | 6 +++++- synapse/media/thumbnailer.py | 6 +++--- 3 files changed, 9 insertions(+), 4 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 0000000000..fe21277a9e --- /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 ecb3edbe3a..c728d6948e 100644 --- a/synapse/config/repository.py +++ b/synapse/config/repository.py @@ -47,7 +47,7 @@ THUMBNAIL_SIZE_YAML = """\ 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/media/thumbnailer.py b/synapse/media/thumbnailer.py index f909a4fb9a..653f3feda4 100644 --- a/synapse/media/thumbnailer.py +++ b/synapse/media/thumbnailer.py @@ -1,5 +1,5 @@ -# Copyright 2014-2016 OpenMarket Ltd -# Copyright 2020-2021 The Matrix.org Foundation C.I.C. +# Copyright 2014-2016,2023 OpenMarket Ltd +# Copyright 2020-2021,2023 The Matrix.org Foundation C.I.C. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -38,7 +38,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: