PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. PIL.Image.crop() method is used to crop a rectangular portion of any image.
Syntax: PIL.Image.crop(box = None)
Parameters:
box – a 4-tuple defining the left, upper, right, and lower pixel coordinate.
Return type: Image (Returns a rectangular region as (left, upper, right, lower)-tuple).
Return: An Image object.
Code #1:
Python3
from PIL import Image
im = Image. open (r "C:\Users\Admin\Pictures\geeks.png" )
width, height = im.size
left = 5
top = height / 4
right = 164
bottom = 3 * height / 4
im1 = im.crop((left, top, right, bottom))
im1.show()
|
Original Image

Output:

Code #2:
Python3
from PIL import Image
im = Image. open (r "C:\Users\Admin\Pictures\network.png" )
left = 155
top = 65
right = 360
bottom = 270
im1 = im.crop((left, top, right, bottom))
im1.show()
|
Original Image:

Output:

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
17 Jun, 2021
Like Article
Save Article