pillow python crop
im = Image.open('image.jpg')
im = im.crop((left, top, width, height))
# ├─input image width─┤
# ┬ ┌───────────────────┐ ┬ ┬
# │ │ │top │
# input │ ┌───────┐ │ ┴ height
# image │ │ │ │ │
# height│ └───────┘ │ ┴
# │ │ │
# ┴ └───────────────────┘
# ├─left─┤
# ├─────width─────┤
4.43
7
im = Image.open('0.png').convert('L')
im = im.crop((1, 1, 98, 33))
im.save('_0.png')
Thank you!
7
0
4
4
im = Image.open('image.jpg')
im = im.crop((left, top, right, bottom)) # coordinates of the crop
Thank you!
4
0
3.67
3
import cv2
img = cv2.imread("lenna.png")
crop_img = img[y:y+h, x:x+w]
cv2.imshow("cropped", crop_img)
cv2.waitKey(0)
Thank you!
3
0
Are there any code examples left?
New code examples in category Python