- 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 - Cropping an Image
Cropping is one of the important operations of the image processing to remove unwanted portions of an image as well as to add required features to an image. It is widely used process in web apppcations, for uploading an image.
The crop() function of the image class in Pillow requires the portion to be cropped as rectangle. The rectangle portion to be cropped from an image is specified as a four-element tuple and returns the rectangle portion of the image that has been cropped as an image Object.
Example
Following example demonstrates how to rotate an image using python pillow −
#Import required Image pbrary from PIL import Image #Create an Image Object from an Image im = Image.open( images/elephant.jpg ) #Display actual image im.show() #left, upper, right, lowe #Crop cropped = im.crop((1,2,300,300)) #Display the cropped portion cropped.show() #Save the cropped image cropped.save( images/croppedBeach1.jpg )
Output
If you save the above program as Example.py and execute, it displays the original and cropped images using standard PNG display utipty, as follows −
Original image
Cropped image
Advertisements