Skip to content

Commit

Permalink
thumbnail WebP as WebP
Browse files Browse the repository at this point in the history
Closes: matrix-org#11840
Signed-off-by: Ronny (tastytea) Gutbrod <tastytea@tastytea.de>
  • Loading branch information
tastytea committed Mar 18, 2023
1 parent 3d70cc3 commit d2f795b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog.d/14890.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Thumbnail WebP images as WebP instead of JPEG, preserving transparency.
6 changes: 5 additions & 1 deletion synapse/config/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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!"
Expand Down
6 changes: 3 additions & 3 deletions synapse/media/thumbnailer.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit d2f795b

Please sign in to comment.