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)
1from PIL import Image
2
3with Image.open("hopper.jpg") as im:
4
5 # The crop method from the Image module takes four coordinates as input.
6 # The right can also be represented as (left+width)
7 # and lower can be represented as (upper+height).
8 (left, upper, right, lower) = (20, 20, 100, 100)
9
10 # Here the image "im" is cropped and assigned to new variable im_crop
11 im_crop = im.crop((left, upper, right, lower))
12