def _handle_resize(self, img, x, y): img_ratio = img.size[0] / img.size[1] target_ratio = x / y if (img_ratio < 1 and target_ratio >= 1) or \ (img_ratio >= 1 and target_ratio < 1): tmp_x = y tmp_y = x tmp_ratio = tmp_x / tmp_y