Python: Resizing and Fitting an Image to an Exact Size

微信扫一扫,分享到朋友圈

Python: Resizing and Fitting an Image to an Exact Size

Often, when working on image analysis in Python, you’d want to resize your images to uniform dimensions (usually, a power of 2). Here is one simple and proven way to resize an image of arbitrary size, down to the exact dimensions you want. If the new dimensions do not match the original ratio, the image will be cropped, starting from the center, in order to match the newly desired ratio.

from PIL import Image, ImageOps

original_image = Image.open("path/to/image")
size = (512, 512)
fit_and_resized_image = ImageOps.fit(original_image, size, Image.ANTIALIAS)

with help from StackOverlow

微信扫一扫,分享到朋友圈

Python: Resizing and Fitting an Image to an Exact Size

这一次,丰田“丰巢”希望以概念造型吸引消费者,能做到吗 | 北京车展

上一篇

小米神速!小米MIX 2S安卓9.0预览版流出

下一篇

你也可能喜欢

Python: Resizing and Fitting an Image to an Exact Size

长按储存图像,分享给朋友