How to set coordinates when cropping an image with PIL?

28,803

How to set the coordinates to crop

In the line:

img2 = img.crop((0, 0, 201, 335))

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:

img2 = img.crop((200, 330, 730, 606))

enter image description here

with the result:

enter image description here

Share:
28,803
Anna K
Author by

Anna K

Updated on March 09, 2021

Comments

  • Anna K
    Anna K about 3 years

    I don't know how to set the coordinates to crop an image in PILs crop():

    from PIL import Image
    img = Image.open("Supernatural.xlsxscreenshot.png")
    img2 = img.crop((0, 0, 201, 335))
    img2.save("img2.jpg")
    

    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:

    enter image description here

    I wish to crop to this:

    enter image description here

  • Anna K
    Anna K over 7 years
    but I pressed the arrow. Is that not as "accepted"? I'm so stupid. Really dont know how to do :(
  • Anna K
    Anna K over 7 years
    Ok. Thank you. I found it finally. I'm sorry that I din't know. Thnak you for your great help :)