imresize() method is used to resize an image in Python, available in the
But unfortunately, this method is now deprecated in
scipy 1.0.0 and will be completely removed from
scipy 1.3.0. So we have to use another way to resize an image in Python.
Resize an Image Using
resize() Method of
PIL Module in Python
PIL is an acronym for Python Imaging Library, which contains some modules for image processing. We can resize an image using the
resize() method of the
Image class available in the
First, install the
pip install pillow
We will import the
Image class from the
PIL module and the
display() method from the
We will put an image in our relative path. Then use the
display() method to display the original image.
from PIL import Image from IPython.display import display print("Original Image") im = Image.open("img.jpg") display(im) resized_im = im.resize((round(im.size*0.5), round(im.size*0.5))) print("Resized Image") display(resized_im) resized_im.save('resized.jpg')
We have resized the image using the
resize() method and passed the length and width of the required image as an
Here we have resized the original image by half its length and width. After that, we have displayed and saved the resized image.