
- Python Pillow - Home
- Python Pillow - Overview
- Python Pillow - Environment Setup
- Basic Image Operations
- Python Pillow - Working with Images
- Python Pillow - Resizing an Image
- Python Pillow - Flip and Rotate Images
- Python Pillow - Cropping an Image
- Python Pillow - Adding Borders to Images
- Python Pillow - Identifying Image Files
- Python Pillow - Merging Images
- Python Pillow - Cutting and Pasting Images
- Python Pillow - Rolling an Image
- Python Pillow - Writing text on image
- Python Pillow - ImageDraw Module
- Python Pillow - Concatenating two Images
- Python Pillow - Creating Thumbnails
- Python Pillow - Creating a Watermark
- Python Pillow - Image Sequences
- Python Pillow Color Conversions
- Python Pillow - Colors on an Image
- Python Pillow - Creating Images With Colors
- Python Pillow - Converting Color String to RGB Color Values
- Python Pillow - Converting Color String to Grayscale Values
- Python Pillow - Change the Color by Changing the Pixel Values
- Image Manipulation
- Python Pillow - Reducing Noise
- Python Pillow - Changing Image Modes
- Python Pillow - Compositing Images
- Python Pillow - Working with Alpha Channels
- Python Pillow - Applying Perspective Transforms
- Image Filtering
- Python Pillow - Adding Filters to an Image
- Python Pillow - Convolution Filters
- Python Pillow - Blur an Image
- Python Pillow - Edge Detection
- Python Pillow - Embossing Images
- Python Pillow - Enhancing Edges
- Python Pillow - Unsharp Mask Filter
- Image Enhancement and Correction
- Python Pillow - Enhancing Contrast
- Python Pillow - Enhancing Sharpness
- Python Pillow - Enhancing Color
- Python Pillow - Correcting Color Balance
- Python Pillow - Removing Noise
- Image Analysis
- Python Pillow - Extracting Image Metadata
- Python Pillow - Identifying Colors
- Advanced Topics
- Python Pillow - Creating Animated GIFs
- Python Pillow - Batch Processing Images
- Python Pillow - Converting Image File Formats
- Python Pillow - Adding Padding to an Image
- Python Pillow - Color Inversion
- Python Pillow - M L with Numpy
- Python Pillow with Tkinter BitmapImage and PhotoImage objects
- Image Module
- Python Pillow - Image Blending
- Python Pillow Useful Resources
- Python Pillow - Quick Guide
- Python Pillow - Function Reference
- Python Pillow - Useful Resources
- Python Pillow - Discussion
Pillow - Cropping an Image
Cropping an image in Pillow (Python Imaging Library) involves selecting a specific region or subarea of an image and creating a new image from that region. This operation is useful for removing unwanted parts of an image and focusing on a particular subject or resizing an image to specific dimensions.
The Image module of the pillow library provides the crop() method to perform the crop operation on the images.
Cropping an Image using the crop() method
Cropping an image can be done by using the crop() method, which allows us to define a box specifying the coordinates of the left, upper, right and lower corners of the region that we want to retain and then it creates a new image with only that portion of the original image.
Here is the basic syntax for the crop() method in Pillow library −
PIL.Image.crop(box)
Where,
box − A tuple specifying the coordinates of the cropping box in the format (left, upper, right, lower). These coordinates represent the left, upper, right and lower edges of the rectangular region we want to retain.
Example
In this example we are cropping the image by using the crop() method by passing the left, upper, right and lower corners of the image region that we want.
from PIL import Image #Open an image image = Image.open("Images/saved_image.jpg") # Display the inaput image image.show() #Define the coordinates for the region to be cropped (left, upper, right, lower) left = 100 upper = 50 right = 300 lower = 250 #Crop the image using the coordinates cropped_image = image.crop((left, upper, right, lower)) #Display the cropped image as a new file cropped_image.show()
Output
The above code will generate the following output −
Input image:

Output image cropped image:

Example
Here this is another example of performing the crop operation of the specified portion of the input image using the crop() method.
from PIL import Image #Open an image image = Image.open("Images/yellow_car.jpg") # Display the inaput image image.show() #Define the coordinates for the region to be cropped (left, upper, right, lower) left = 100 upper = 100 right = 300 lower = 300 #Crop the image using the coordinates cropped_image = image.crop((left, upper, right, lower)) #Display the cropped image cropped_image.show()
Output
On executing the above code you will get the following output −
Input image:

Output cropped image:
