diff --git a/src/PIL/ImageOps.py b/src/PIL/ImageOps.py index 0c3f900ca..df40e4c4e 100644 --- a/src/PIL/ImageOps.py +++ b/src/PIL/ImageOps.py @@ -20,7 +20,7 @@ import functools import operator import re - +import math from . import Image # @@ -255,11 +255,11 @@ def contain(image, size, method=Image.Resampling.BICUBIC): if im_ratio != dest_ratio: if im_ratio > dest_ratio: - new_height = int(image.height / image.width * size[0]) + new_height = math.ceil(image.height / image.width * size[0]) if new_height != size[1]: size = (size[0], new_height) else: - new_width = int(image.width / image.height * size[1]) + new_width = math.ceil(image.width / image.height * size[1]) if new_width != size[0]: size = (new_width, size[1]) return image.resize(size, resample=method)