Python | Crop image using pillow

In this article, we will learn to crop an image using pillow library. Cropping an image means to select a rectangular region inside an image and removing everything outside the rectangle. To crop an image we make use of crop() method on image objects.

Syntax : IMG.crop(box_tuple)

Parameters :
Image_path- Location of the image
IMG- Image to crop
box_tuple- [left, up, right, bottom] of the image to crop



Returns : An Image object which represents the cropped image.

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# import Image module
from PIL import Image
  
# open the image
Image1 = Image.open('D:/cat.jpg')
  
# crop the image
croppedIm = Image1.crop((130, 120, 200, 200))
  
# show the image
croppedIm.show()

chevron_right


Input Image :

Ouput :

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# import Image module
from PIL import Image
  
# open the image
Image1 = Image.open('D:/cat.jpg')
  
# crop the image
croppedIm = Image1.crop((130, 50, 250, 150))
  
# show the image
croppedIm.show()

chevron_right


Input Image :

Ouput :



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.