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

Commit 6ce19b9

Browse files
authored
Fix error in thumbnail generation (#11288)
Signed-off-by: Jonas Zeunert <[email protected]>
1 parent 5cace20 commit 6ce19b9

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

changelog.d/11288.bugfix

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a long-standing bug where uploading extremely thin images (e.g. 1000x1) would fail. Contributed by @Neeeflix.

synapse/rest/media/v1/thumbnailer.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,18 @@ def aspect(self, max_width: int, max_height: int) -> Tuple[int, int]:
101101
fits within the given rectangle::
102102
103103
(w_in / h_in) = (w_out / h_out)
104-
w_out = min(w_max, h_max * (w_in / h_in))
105-
h_out = min(h_max, w_max * (h_in / w_in))
104+
w_out = max(min(w_max, h_max * (w_in / h_in)), 1)
105+
h_out = max(min(h_max, w_max * (h_in / w_in)), 1)
106106
107107
Args:
108108
max_width: The largest possible width.
109109
max_height: The largest possible height.
110110
"""
111111

112112
if max_width * self.height < max_height * self.width:
113-
return max_width, (max_width * self.height) // self.width
113+
return max_width, max((max_width * self.height) // self.width, 1)
114114
else:
115-
return (max_height * self.width) // self.height, max_height
115+
return max((max_height * self.width) // self.height, 1), max_height
116116

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

0 commit comments

Comments
 (0)