tags:

views:

1032

answers:

1

Im attempting to crop a pretty high res image and save the result to make sure its completed. However I keep getting the following error regardless of how I use the save method: SystemError: tile cannot extend outside image

from PIL import Image

# size is width/height
img = Image.open('0_388_image1.jpeg')
box = (2407, 804, 71, 796)
area = img.crop(box)

area.save('cropped_0_388_image1', 'jpeg')
output.close()
+5  A: 

The box is (left, upper, right, lower) so maybe you meant (2407, 804, 2407+71, 804+796)?

Edit: All four coordinates are measured from the top/left corner, and describe the distance from that corner to the left edge, top edge, right edge and bottom edge.

Your code should look like this, to get a 300x200 area from position 2407,804:

left = 2407
top = 804
width = 300
height = 200
box = (left, top, left+width, top+height)
area = img.crop(box)
RichieHindle
:) Yes indeed the image is that big. Its almost 1Mg .. its an image of an intersectionwhat i understood is this: the documentation says left upper(top) right lower(bottom) which is EXACTLY what I put in. The pixel coords are 2407 from the LEFT 804 pixels from the TOP 71 pixels from the RIGHT and 796 pixels from the BOTTOM. I dont see where I erred. the box thus described crops a vehicle's back end
Matt1776
All the coordinates are measured from the top/left corner, and describe the distance from that corner to the left edge, top edge, right edge and bottom edge.
RichieHindle
I must be retarded. I tried what I thought you meant and now its a small little sliver:box = (1465, 1788, 3801, 1796)
Matt1776
oh my GOD. Am I stupid? Was that obvious? And what happened to the other guy? he didnt want to be seen on this thread ?? ;0)
Matt1776
Thank you. this was very helpful
Matt1776
My pleasure! (I see you're new to Stack Overflow... the correct etiquette at this point is to Accept this answer by clicking the tick on the left of the question.)
RichieHindle
Got it. Why must I comment on everyones response? why cant I comment once for everyone?
Matt1776
Thanks! To say something to everyone, you should edit your question.
RichieHindle