Tags: crop, description, method, needto, pil, programming, python, target

PIL question about crop method

On Programmer » Python

6,059 words with 6 Comments; publish: Wed, 02 Jan 2008 20:43:00 GMT; (20064.45, « »)

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?

Thanks.

All Comments

Leave a comment...

  • 6 Comments
    • 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

      #1; Wed, 02 Jan 2008 20:44:00 GMT
    • John Salerno wrote:

      >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?

      >Thanks.

      >

      If you want the cropped rectangle to go from 100 to 200 in x and 300 to

      400 in y, then those four values need to be placed in a tuple in the

      specified order:

      box=(100,300,200,400)

      Gary Herron

      #2; Wed, 02 Jan 2008 20:45:00 GMT
    • Diez B. Roggisch wrote:

      > Alternatively you can see it as boundary lines, in the order left, top,

      > right, bottom.

      > (10, 20, 30, 100)

      So in the above, from where are the numbers being counted? 10 is ten

      pixels from the left border of the image? 20 is twenty pixels from the

      top border? But is 30 thirty pixels from the left or the right border of

      the image? And is 100 one hundred pixels from the top or bottom?

      #3; Wed, 02 Jan 2008 20:46:00 GMT
    • John Salerno wrote:

      > Diez B. Roggisch wrote:

      >> Alternatively you can see it as boundary lines, in the order left,

      >> top, right, bottom.

      >>

      >> (10, 20, 30, 100)

      > So in the above, from where are the numbers being counted? 10 is ten

      > pixels from the left border of the image? 20 is twenty pixels from the

      > top border? But is 30 thirty pixels from the left or the right border of

      > the image? And is 100 one hundred pixels from the top or bottom?

      I came up with this, is it correct:

      (a,b) (c,b)

      ------

      | |

      | |

      ------

      (a,d) (c,d)

      So the tuple would be (a, b, c, d)?

      #4; Wed, 02 Jan 2008 20:47:00 GMT
    • Yes

      John Salerno wrote:

      > John Salerno wrote:

      >> Diez B. Roggisch wrote:

      >>

      >>> Alternatively you can see it as boundary lines, in the order left,

      >>> top, right, bottom.

      >>>

      >>> (10, 20, 30, 100)

      >>

      >> So in the above, from where are the numbers being counted? 10 is ten

      >> pixels from the left border of the image? 20 is twenty pixels from the

      >> top border? But is 30 thirty pixels from the left or the right border of

      >> the image? And is 100 one hundred pixels from the top or bottom?

      > I came up with this, is it correct:

      > (a,b) (c,b)

      > ------

      > | |

      > | |

      > ------

      > (a,d) (c,d)

      >

      > So the tuple would be (a, b, c, d)?

      #5; Wed, 02 Jan 2008 20:48:00 GMT
    • John Salerno wrote:

      >John Salerno wrote:

      >

      >>Diez B. Roggisch wrote:

      >>

      >>

      >>

      >>>Alternatively you can see it as boundary lines, in the order left,

      >>>top, right, bottom.

      >>>

      >>>(10, 20, 30, 100)

      >>>

      >>>

      >>So in the above, from where are the numbers being counted? 10 is ten

      >>pixels from the left border of the image? 20 is twenty pixels from the

      >>top border? But is 30 thirty pixels from the left or the right border of

      >>the image? And is 100 one hundred pixels from the top or bottom?

      >>

      >>

      >I came up with this, is it correct:

      >(a,b) (c,b)

      > ------

      > | |

      > | |

      > ------

      >(a,d) (c,d)

      >

      >So the tuple would be (a, b, c, d)?

      >

      That look right.

      But why be so cautious? Try it and see if it works. (I believe it will

      -- but if not -- try again.)

      Gary Herron

      #6; Wed, 02 Jan 2008 20:49:00 GMT