thumbnail WebP as WebP

Closes: https://github.com/matrix-org/synapse/issues/11840
Signed-off-by: Ronny (tastytea) Gutbrod <tastytea@tastytea.de>
pull/14890/head
tastytea 2022-10-27 18:44:06 +02:00
parent 3d70cc393f
commit d2f795b87d
No known key found for this signature in database
3 changed files with 9 additions and 4 deletions

1
changelog.d/14890.bugfix Normal file
View File

@ -0,0 +1 @@
Thumbnail WebP images as WebP instead of JPEG, preserving transparency.

View File

@ -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!"

View File

@ -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: