Skip to content

Commit

Permalink
thumbnail WebP as WebP
Browse files Browse the repository at this point in the history
  • Loading branch information
tastytea committed Jan 21, 2023
1 parent 8d90e5f commit b62d4ab
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 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
2 changes: 1 addition & 1 deletion synapse/rest/media/v1/thumbnailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit b62d4ab

Please sign in to comment.