imgutils.operate.align

Overview:

A utility for aligning dimensions based on the size of an image.

align_maxsize

imgutils.operate.align.align_maxsize(image: str | PathLike | bytes | bytearray | BinaryIO | Image, max_size: int) Image[source]

Resizes the image while maintaining its aspect ratio, ensuring that the length of its longer side aligns with the given max_size.

Parameters:
  • image – The input image to be resized.

  • max_size – The maximum length of the longer side after resizing.

Returns:

The resized image.

Example::
>>> from PIL import Image
>>> from imgutils.operate import align_maxsize
>>>
>>> image = Image.open('genshin_post.jpg')
>>> image.size
(1280, 720)
>>>
>>> new_img = align_maxsize(image, max_size=600)
>>> new_img.size
(600, 337)