- Python Pillow Tutorial
- Python Pillow - Home
- Python Pillow - Overview
- Python Pillow - Environment Setup
- Python Pillow - Using Image Module
- Python Pillow - Working with Images
- Python Pillow - Creating Thumbnails
- Python Pillow - Merging Images
- Python Pillow - Blur an Image
- Python Pillow - Cropping an Image
- Python Pillow - Flip and Rotate Images
- Python Pillow - Resizing an Image
- Python Pillow - Creating a Watermark
- Python Pillow - Adding Filters to an Image
- Python Pillow - Colors on an Image
- Python Pillow - ImageDraw Module
- Python Pillow - Image Sequences
- Python Pillow - Writing Text on Image
- Python Pillow - M L with Numpy
- Python Pillow Useful Resources
- Python Pillow - Quick Guide
- Python Pillow - Useful Resources
- Python Pillow - Discussion
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 applications, 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 library 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 utility, as follows −
Original image
Cropped image
To Continue Learning Please Login
Login with Google