Python Pillow Tutorial
Selected Reading
- 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 - Resizing an Image
Python Pillow - Resizing an Image
Most of the digital image is a two-dimensional plane of pixels and it has a width and height. The Image module from pillow pbrary has an attribute size. This tuple consists of width and height of the image as its elements. To resize an image, you call the resize() method of pillow’s image class by giving width and height.
Resize and save the resized image
The program for resizing and saving the resized image is given below −
#Import required Image pbrary from PIL import Image #Create an Image Object from an Image im = Image.open("images/cat.jpg") #Display actual image im.show() #Make the new image half the width and half the height of the original image resized_im = im.resize((round(im.size[0]*0.5), round(im.size[1]*0.5))) #Display the resized imaged resized_im.show() #Save the cropped image resized_im.save( resizedBeach1.jpg )
Output
If you save the above program as Example.py and execute, it displays the original and resized images using standard PNG display utipty, as follows −
Original Image
Resized Image
Advertisements