Skip to content

Commit 7427875

Browse files
authored
Fix weird resized width and height if the difference of image ratio is large (#18)
* remove job `github-release` * fix giant factor if image ratio is too large * keep `reg_w` and `reg_h` unchange if it's already multiply of strides
1 parent 88bb23b commit 7427875

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

wpodnet/backend.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,17 @@ def _resize_to_fixed_ratio(self, image: Image.Image, dim_min: int, dim_max: int)
5858
side = int(wh_ratio * dim_min)
5959
bound_dim = min(side + side % self._stride, dim_max)
6060

61-
factor = bound_dim / min(h, w)
61+
factor = bound_dim / max(h, w)
6262
reg_w, reg_h = int(w * factor), int(h * factor)
6363

6464
# Ensure the both width and height are the multiply of `self._stride`
65-
reg_w += self._stride - reg_w % self._stride
66-
reg_h += self._stride - reg_h % self._stride
65+
reg_w_mod = reg_w % self._stride
66+
if reg_w_mod > 0:
67+
reg_w += self._stride - reg_w_mod
68+
69+
reg_h_mod = reg_h % self._stride
70+
if reg_h_mod > 0:
71+
reg_h += self._stride - reg_h % self._stride
6772

6873
return image.resize((reg_w, reg_h))
6974

0 commit comments

Comments
 (0)