@@ -242,7 +242,7 @@ def contain(image, size, method=Image.Resampling.BICUBIC):
242242 Returns a resized version of the image, set to the maximum width and height
243243 within the requested size, while maintaining the original aspect ratio.
244244
245- :param image: The image to resize and crop .
245+ :param image: The image to resize.
246246 :param size: The requested output size in pixels, given as a
247247 (width, height) tuple.
248248 :param method: Resampling method to use. Default is
@@ -266,6 +266,35 @@ def contain(image, size, method=Image.Resampling.BICUBIC):
266266 return image .resize (size , resample = method )
267267
268268
269+ def cover (image , size , method = Image .Resampling .BICUBIC ):
270+ """
271+ Returns a resized version of the image, set to at least the width and
272+ height of the requested size, while maintaining the original aspect ratio.
273+
274+ :param image: The image to resize.
275+ :param size: The requested output size in pixels, given as a
276+ (width, height) tuple.
277+ :param method: Resampling method to use. Default is
278+ :py:attr:`~PIL.Image.Resampling.BICUBIC`.
279+ See :ref:`concept-filters`.
280+ :return: An image.
281+ """
282+
283+ im_ratio = image .width / image .height
284+ dest_ratio = size [0 ] / size [1 ]
285+
286+ if im_ratio != dest_ratio :
287+ if im_ratio < dest_ratio :
288+ new_height = round (image .height / image .width * size [0 ])
289+ if new_height != size [1 ]:
290+ size = (size [0 ], new_height )
291+ else :
292+ new_width = round (image .width / image .height * size [1 ])
293+ if new_width != size [0 ]:
294+ size = (new_width , size [1 ])
295+ return image .resize (size , resample = method )
296+
297+
269298def pad (image , size , method = Image .Resampling .BICUBIC , color = None , centering = (0.5 , 0.5 )):
270299 """
271300 Returns a resized and padded version of the image, expanded to fill the
0 commit comments