I don’t know how to set the coordinates to crop an image in PIL
s crop()
:
JavaScript
x
5
1
from PIL import Image
2
img = Image.open("Supernatural.xlsxscreenshot.png")
3
img2 = img.crop((0, 0, 201, 335))
4
img2.save("img2.jpg")
5
I tried with gThumb
to get coordinates, but if I take an area which I would like to crop, I can only find position 194 336. Could someone help me please?
This is my picture:
I wish to crop to this:
Advertisement
Answer
How to set the coordinates to crop
In the line:
JavaScript
1
2
1
img2 = img.crop((0, 0, 201, 335))
2
the first two numbers define the top-left coordinates of the outtake (x,y), while the last two define the right-bottom coordinates of the outtake.
Cropping your image
To crop your image like you show, I found the following coordinates: top-left: (200, 330)
, and right-bottom: (730, 606)
. Subsequently, I cropped your image with:
JavaScript
1
2
1
img2 = img.crop((200, 330, 730, 606))
2
with the result: