调整大小并保存调整大小的图像
调整大小和保存调整大小图像的程序如下 -
#Import required Image library
from PIL import Image
#Create an Image Object from an Image
im = Image.open("images/cat.jpg")
#Display actual image
im.show()
#Make the new image half the width and half the height of the original image
resized_im = im.resize((round(im.size[0]*0.5), round(im.size[1]*0.5)))
#Display the resized imaged
resized_im.show()
#Save the cropped image
resized_im.save('resizedBeach1.jpg')
输出
如果将上述程序另存为 Example.py 并执行,它将使用标准 PNG 显示实用程序显示原始图像和调整大小的图像,如下所示 -
Original Image
Resized Image