How to crop image using Python

Image cropping is very easy using python library Pillow. Following is simple program to crop image in required parts.

Most important part of cropping is to know pixel size of your image, you can crop required portion using .crop method of Image module of Pillow.

Sample program

https://gist.github.com/conquistadorjd/2c93de1d95fa1a953c2221efc4420c4b#file-06_crop_image_01-py

Please note that crop takes tupleĀ  having four values as input. These four values represent left, upper, right, lower point .

Original image

Left Half of the image

Right Half of the image

Top Right corner of the image

Here is the output of the program, please note the pixel size of each cropped image.

$ python3.6 06_crop_image_01.py 
*** Program Started ***
im.size (1920, 1318)
im.size (960, 1318)
im.size (960, 1318)
im.size (960, 659)
*** Program Ended ***
CategoriesUncategorized

Leave a Reply

Your email address will not be published. Required fields are marked *