How to crop an image in PIL (Pillow Python)

In this article, you’ll see how to crop an image in PIL Python. To crop an image you have to specify the exact position (points). In the following example, (0,0) is the start point, and (500, 300) is the endpoint.

# Import the PIL library
from PIL import Image

# Read the image from location
img ="C:\\AiHints\\cats.jpg")

# Crop the Image
crop_img = img.crop((0,0, 500,300)) 

# Show the Cropped Image

# Save the Cropped Image"C:\\AiHints\\Cropped_Image.jpg")


crop an image in PIL

Recommendation: Computer Vision: Models, Learning, and Inference Book

Leave a Comment

Your email address will not be published.