Skip to content
Snippets Groups Projects
Unverified Commit 6ce19b94 authored by Neeeflix's avatar Neeeflix Committed by GitHub
Browse files

Fix error in thumbnail generation (#11288)


Signed-off-by: default avatarJonas Zeunert <jonas@zeunert.org>
parent 5cace20b
No related branches found
No related tags found
No related merge requests found
Fix a long-standing bug where uploading extremely thin images (e.g. 1000x1) would fail. Contributed by @Neeeflix.
...@@ -101,8 +101,8 @@ class Thumbnailer: ...@@ -101,8 +101,8 @@ class Thumbnailer:
fits within the given rectangle:: fits within the given rectangle::
(w_in / h_in) = (w_out / h_out) (w_in / h_in) = (w_out / h_out)
w_out = min(w_max, h_max * (w_in / h_in)) w_out = max(min(w_max, h_max * (w_in / h_in)), 1)
h_out = min(h_max, w_max * (h_in / w_in)) h_out = max(min(h_max, w_max * (h_in / w_in)), 1)
Args: Args:
max_width: The largest possible width. max_width: The largest possible width.
...@@ -110,9 +110,9 @@ class Thumbnailer: ...@@ -110,9 +110,9 @@ class Thumbnailer:
""" """
if max_width * self.height < max_height * self.width: 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: 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: def _resize(self, width: int, height: int) -> Image.Image:
# 1-bit or 8-bit color palette images need converting to RGB # 1-bit or 8-bit color palette images need converting to RGB
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment