Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Fix error in thumbnail generation (#11288)
Browse files Browse the repository at this point in the history
Signed-off-by: Jonas Zeunert <jonas@zeunert.org>
  • Loading branch information
Neeeflix committed Nov 10, 2021
1 parent 5cace20 commit 6ce19b9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog.d/11288.bugfix
@@ -0,0 +1 @@
Fix a long-standing bug where uploading extremely thin images (e.g. 1000x1) would fail. Contributed by @Neeeflix.
8 changes: 4 additions & 4 deletions synapse/rest/media/v1/thumbnailer.py
Expand Up @@ -101,18 +101,18 @@ def aspect(self, max_width: int, max_height: int) -> Tuple[int, int]:
fits within the given rectangle::
(w_in / h_in) = (w_out / h_out)
w_out = min(w_max, h_max * (w_in / h_in))
h_out = min(h_max, w_max * (h_in / w_in))
w_out = max(min(w_max, h_max * (w_in / h_in)), 1)
h_out = max(min(h_max, w_max * (h_in / w_in)), 1)
Args:
max_width: The largest possible width.
max_height: The largest possible height.
"""

if max_width * self.height < max_height * self.width:
return max_width, (max_width * self.height) // self.width
return max_width, max((max_width * self.height) // self.width, 1)
else:
return (max_height * self.width) // self.height, max_height
return max((max_height * self.width) // self.height, 1), max_height

def _resize(self, width: int, height: int) -> Image.Image:
# 1-bit or 8-bit color palette images need converting to RGB
Expand Down

0 comments on commit 6ce19b9

Please sign in to comment.