The Wayback Machine - https://web.archive.org/web/20240718005004/https://www.geeksforgeeks.org/python-pil-image-resize-method/
Open In App

Python PIL | Image.resize() method

Last Updated : 31 Mar, 2023
Improve
Suggest changes
Post a comment
Like Article
Like
Save
Share
Report

PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The Image module provides a class with the same name which is used to represent a PIL image. The module also provides a number of factory functions, including functions to load images from files, and to create new images.
Image.resize() Returns a resized copy of this image.
 

Syntax: Image.resize(size, resample=0) 
Parameters: 
size – The requested size in pixels, as a 2-tuple: (width, height). 
resample – An optional resampling filter. This can be one of PIL.Image.NEAREST (use nearest neighbour), PIL.Image.BILINEAR (linear interpolation), PIL.Image.BICUBIC (cubic spline interpolation), or PIL.Image.LANCZOS (a high-quality downsampling filter). If omitted, or if the image has mode “1” or “P”, it is set PIL.Image.NEAREST. Otherwise, the default filter is Resampling.BICUBIC. 
Returns type: An Image object.

Source
 

Image Used: 
 

 

Python3




# Importing Image class from PIL module
from PIL import Image
 
# Opens a image in RGB mode
im = Image.open(r"C:\Users\System-Pc\Desktop\ybear.jpg")
 
# Size of the image in pixels (size of original image)
# (This is not mandatory)
width, height = im.size
 
# Setting the points for cropped image
left = 4
top = height / 5
right = 154
bottom = 3 * height / 5
 
# Cropped image of above dimension
# (It will not change original image)
im1 = im.crop((left, top, right, bottom))
newsize = (300, 300)
im1 = im1.resize(newsize)
# Shows the image in image viewer
im1.show()


Output: 
 

Another example:Here we use the different newsize value.
 

Python3




# Importing Image class from PIL module
from PIL import Image
 
# Opens a image in RGB mode
im = Image.open(r"C:\Users\System-Pc\Desktop\ybear.jpg")
 
# Size of the image in pixels (size of original image)
# (This is not mandatory)
width, height = im.size
 
# Setting the points for cropped image
left = 6
top = height / 4
right = 174
bottom = 3 * height / 4
 
# Cropped image of above dimension
# (It will not change original image)
im1 = im.crop((left, top, right, bottom))
newsize = (200, 200)
im1 = im1.resize(newsize)
# Shows the image in image viewer
im1.show()


Output: 
 

 



Previous Article
Next Article

Similar Reads

Convert OpenCV image to PIL image in Python
OpenCV is a huge open-source library for computer vision, machine learning, and image processing. OpenCV supports a wide variety of programming languages like Python, C++, Java, etc. It can process images and videos to identify objects, faces, or even the handwriting of a human. When it is integrated with various libraries, such as Numpy which is a
3 min read
How to merge a transparent PNG image with another image using PIL?
This article discusses how to put a transparent PNG image with another image. This is a very common operation on images. It has a lot of different applications. For example, adding a watermark or logo on an image. To do this, we are using the PIL module in Python. In which we use some inbuilt methods and combine the images in such a way that it loo
2 min read
Python PIL | Image.crop() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. PIL.Image.crop() method is used to crop a rectangular portion of any image. Syntax: PIL.Image.crop(box = None)Parameters: box - a 4-tuple defining the left, upper, right, and lower pixel coordinate.Return type: Image (Returns a rectangular regio
2 min read
Python PIL | Image.new() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. PIL.Image.new() method creates a new image with the given mode and size. Size is given as a (width, height)-tuple, in pixels. The color is given as a single value for single-band images, and a tuple for multi-band images (with one value for each
2 min read
Python PIL | Image.split() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. Image.split() method is used to split the image into individual bands. This method returns a tuple of individual image bands from an image. Splitting an “RGB” image creates three new images each containing a copy of one of the original bands (re
1 min read
Python PIL | Image.open() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The Image module provides a class with the same name which is used to represent a PIL image. The module also provides a number of factory functions, including functions to load images from files, and to create new images. PIL.Image.open() Opens
2 min read
Python PIL | Image.point() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The Image module provides a class with the same name which is used to represent a PIL image. The module also provides a number of factory functions, including functions to load images from files, and to create new images. Image.point() Maps this
2 min read
Python PIL | Image.show() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The Image module provides a class with the same name which is used to represent a PIL image. The module also provides a number of factory functions, including functions to load images from files, and to create new images.Image.show() Displays th
1 min read
Python PIL | Image.save() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The Image module provides a class with the same name which is used to represent a PIL image. The module also provides a number of factory functions, including functions to load images from files, and to create new images. Image.save() Saves this
2 min read
Python PIL | Image.quantize() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The Image module provides a class with the same name which is used to represent a PIL image. The module also provides a number of factory functions, including functions to load images from files, and to create new images. Image.quantize() Conver
1 min read
Article Tags :
Practice Tags :
three90RightbarBannerImg