Skip to content
Related Articles

Related Articles

Improve Article

Python PIL | Image.thumbnail() Method

  • Last Updated : 19 Jul, 2019

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:

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course




My Personal Notes arrow_drop_up
Recommended Articles
Page :