1im = Image.open('image.jpg')
2im = im.crop((left, top, width, height))
3
4# ├─input image width─┤
5# ┬ ┌───────────────────┐ ┬ ┬
6# │ │ │top │
7# input │ ┌───────┐ │ ┴ height
8# image │ │ │ │ │
9# height│ └───────┘ │ ┴
10# │ │ │
11# ┴ └───────────────────┘
12# ├─left─┤
13# ├─────width─────┤
1im = Image.open('image.jpg')
2im = im.crop((left, top, right, bottom)) # coordinates of the crop
1from PIL import Image # import pillow library (can install with "pip install pillow")
2im = Image.open('card.png')
3im = im.crop( (1, 0, 826, 1125) ) # previously, image was 826 pixels wide, cropping to 825 pixels wide
4im.save('card.png') # saves the image
5# im.show() # opens the image
1import cv2
2img = cv2.imread("lenna.png")
3crop_img = img[y:y+h, x:x+w]
4cv2.imshow("cropped", crop_img)
5cv2.waitKey(0)