PIL question about crop method

Diez B. Roggisch deets at nospam.web.de
Wed Apr 5 14:56:27 EDT 2006


John Salerno schrieb:
> I might be way off target even looking into this method for what I need 
> to do, but I'm still a little confused about the description of it:
> 
> crop
> im.crop(box) => image
> 
> Returns a rectangular region from the current image. The box is a 
> 4-tuple defining the left, upper, right, and lower pixel coordinate.
> 
> I'm probably just being a little dense again, but how exactly do you 
> write the tuple? Wouldn't a coordinates parameter be a tuple of tuples? 
> It sounds like here you only need four numbers, but I don't understand 
> what 'left, upper, right, and lower pixel coordinate' means. It doesn't 
> seem like it's asking for a set of coordinates for each corner of the 
> box, or for a set at all. How do four separate numbers make up coordinates?

You can think of a rect as two coordinates - e.g. (10, 20), (30, 100)

Alternatively you can see it as boundary lines, in the order left, top, 
right, bottom.

(10, 20, 30, 100)

The latter is what you need.

Diez



More information about the Python-list mailing list