tags:

views:

887

answers:

2

Can't seem to get crop working correctly, problem is, it crops a region of correct dimensions, but always from top left corner (0, 0), instead of from my passed coordinates.

image = Image.open(input)
region = image.crop((1000,400,2000,600)
region.save(output)

In image.py from PIL, method _ImageCrop I've printed out.. :

print x0, y0, x1, y1
self.__crop = x0, y0, x1, y1

Values seem to be correct.

Input is a JPEG image of size 1600x2390.

Python version: 2.5, PIL version: 1.1.6

Any suggestions? Thanks

+1  A: 

Works For Me: Python 2.6.1, PIL 1.1.6, JPEG of size 2020x1338 pixels.

Are you sure you mean a JPEG of 1600x2390 and not 2390x1600? The (1000,400,2000,600) box dimensions are outside the size of a 1600-wide image; if I try this I get garbage data outside the intersecting area.

bobince
A: 

I`m do next:

cover=Image.open(path_to_cover+"/shablon1.jpg")

....

def generit_nomer_proekt(self,nomer):
    size_box=(160,40)
    font=ImageFont.truetype('/home/vintello/workspace/mpg_to_dvd/src/cover/ttf/aricyr.ttf',int(30))
    im = Image.new ( "RGB", size_box , "white" )
    draw = ImageDraw.Draw ( im )
    draw.text ( (20,0), unicode(nomer,"utf-8"), fill="#74716f", font=font )
    return im

.....

nazv_vert=self.generit_nomer_proekt(nomer)
coo=nazv_vert.size
left_x=1575
left_y=383
box_vert_nazv=(left_x,left_y,left_x+coo[0],left_y+coo[1])
cover.paste(nazv_vert,box_vert_nazv)

or if you wont as PNG past use:

cover.paste(nazv_vert,box_vert_nazv,nazv_vert)