List Info

Thread: crop question




crop question
user name
2007-02-13 11:48:47
I am trying to take an existing image and split it into
equally sized
tiles.  When I try to save a "cropped" image I get
the following
error:

"tile cannot extend outside image"

The first pass saves the first tile correctly, the second
one chokes
and blurts the error.

Following is some code to illustrate my confusion:

original_image = Image.open("big_image.tif")

# math stuff
w, h = orig.size
self.tile_width = w = w/self.tiles_across
self.tile_height = h = h/self.tiles_down

for y in range (self.tiles_down):

    for x in range (self.tiles_across):

        box = (x * w, y * h, w, h)
        tim = original_image.crop(box)
        tim.save("test.tif")

Advice super appreciated!

Thank You ~ j
_______________________________________________
Image-SIG maillist  -  Image-SIGpython.org
htt
p://mail.python.org/mailman/listinfo/image-sig

Re: crop question
country flaguser name
United States
2007-02-13 16:12:26
Jason Van Anden wrote:
> I am trying to take an existing image and split it into
equally sized
> tiles.  When I try to save a "cropped" image
I get the following
> error:
>
> "tile cannot extend outside image"
>
> The first pass saves the first tile correctly, the
second one chokes
> and blurts the error.
>
> Following is some code to illustrate my confusion:
>
> original_image = Image.open("big_image.tif")
>
> # math stuff
> w, h = orig.size
> self.tile_width = w = w/self.tiles_across
> self.tile_height = h = h/self.tiles_down
>
> for y in range (self.tiles_down):
>
>     for x in range (self.tiles_across):
>
>         box = (x * w, y * h, w, h)
>         tim = original_image.crop(box)
>         tim.save("test.tif")
>
> Advice super appreciated!
>
> Thank You ~ j
>   
Crop uses right and lower instead of width and height for
the last two 
elements of the box.


      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.


- Ken


_______________________________________________
Image-SIG maillist  -  Image-SIGpython.org
htt
p://mail.python.org/mailman/listinfo/image-sig

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )