Open In App
Related Articles

Python PIL | Image.thumbnail() Method

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
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.thumbnail() Make this image into a thumbnail. This method modifies the image to contain a thumbnail version of itself, no larger than the given size. This method calculates an appropriate thumbnail size to preserve the aspect of the image, calls the draft() method to configure the file reader (where applicable), and finally resizes the image. Note that this function modifies the Image object in place. If you need to use the full resolution image as well, apply this method to a copy() of the original image.
Syntax: Image.thumbnail(size, resample=3) Parameters: size – Requested size. resample – Optional resampling filter. Returns Type: An Image object.
Image Used:
   
  
# importing Image class from PIL package 
from PIL import Image
   
# creating a object 
image = Image.open(r"C:\Users\System-Pc\Desktop\python.png")
MAX_SIZE = (100, 100)
  
image.thumbnail(MAX_SIZE)
  
# creating thumbnail
image.save('pythonthumb.png')
image.show()

                    
Output: Another Example:Here used another image. Image Used:
   
  
# importing Image class from PIL package 
from PIL import Image
   
# creating a object 
image = Image.open(r"C:\Users\System-Pc\Desktop\house.jpg")
MAX_SIZE = (500, 500)
  
image.thumbnail(MAX_SIZE)
  
# creating thumbnail
image.save('pythonthumb2.jpg')
image.show()

                    
Output:

Last Updated : 19 Jul, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads