Python Pillow - Resizing an Image


Most of the digital image is a two-dimensional plane of pixels and it has a width and height. The Image module from pillow library has an attribute size. This tuple consists of width and height of the image as its elements. To resize an image, you call the resize() method of pillow’s image class by giving width and height.

Resize and save the resized image

The program for resizing and saving the resized image is given below −

#Import required Image library
from PIL import Image

#Create an Image Object from an Image
im ="images/cat.jpg")

#Display actual image

#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

#Save the cropped image'resizedBeach1.jpg')


If you save the above program as and execute, it displays the original and resized images using standard PNG display utility, as follows −

Original Image

Original Image

Resized Image