- Python Pillow - Discussion
- Python Pillow - Useful Resources
- Python Pillow - Quick Guide
- Python Pillow - M L with Numpy
- Python Pillow - Writing Text on Image
- Python Pillow - Image Sequences
- Python Pillow - ImageDraw Module
- Python Pillow - Colors on an Image
- Python Pillow - Adding Filters to an Image
- Python Pillow - Creating a Watermark
- Python Pillow - Resizing an Image
- Python Pillow - Flip and Rotate Images
- Python Pillow - Cropping an Image
- Python Pillow - Blur an Image
- Python Pillow - Merging Images
- Python Pillow - Creating Thumbnails
- Python Pillow - Working with Images
- Python Pillow - Using Image Module
- Python Pillow - Environment Setup
- Python Pillow - Overview
- Python Pillow - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Python Pillow - Creating Thumbnails
Sometimes, it is required to have all images of equal height and width. One way to achieve this, is by creating a thumbnail of all images using the thumbnail() function from pillow pbrary.
This method modifies the image to contain a thumbnail version of itself and the size of the image will be no larger than the given size.
The method calculates an appropriate thumbnail size to preserve the aspect of the image, calls the draft () method to configure the file reader (where apppcable) and finally, resizes the image.
Syntax
Image.thumbnail(size, resample=3)
Where,
Size − Required size
Resample − Optional resamppng filter. It can be one of these PIL.Image.NEAREST, PIL.Image.BILINEAR, PIL.Image.BICUBIC, or PIL.Image.LANCZOS. If omitted, it defaults to PIL.Image.BICUBIC.
Returns − None
Example
Following example demonstrates the creation of a thumbnail using python pillow −
from PIL import Image def tnails(): try: image = Image.open( images/cat.jpg ) image.thumbnail((90,90)) image.save( images/thumbnail.jpg ) image1 = Image.open( images/thumbnail.jpg ) image1.show() except IOError: pass tnails()
Output
If you save the above program as Example.py and execute, it displays the created thumbnail using the default PNG display utipty, as follows −
Original image
Output image
Advertisements