diff --git a/wpodnet/backend.py b/wpodnet/backend.py index c28479c..c251944 100644 --- a/wpodnet/backend.py +++ b/wpodnet/backend.py @@ -58,12 +58,17 @@ def _resize_to_fixed_ratio(self, image: Image.Image, dim_min: int, dim_max: int) side = int(wh_ratio * dim_min) bound_dim = min(side + side % self._stride, dim_max) - factor = bound_dim / min(h, w) + factor = bound_dim / max(h, w) reg_w, reg_h = int(w * factor), int(h * factor) # Ensure the both width and height are the multiply of `self._stride` - reg_w += self._stride - reg_w % self._stride - reg_h += self._stride - reg_h % self._stride + reg_w_mod = reg_w % self._stride + if reg_w_mod > 0: + reg_w += self._stride - reg_w_mod + + reg_h_mod = reg_h % self._stride + if reg_h_mod > 0: + reg_h += self._stride - reg_h % self._stride return image.resize((reg_w, reg_h))