简体   繁体   English

Python,PIL,作物问题

[英]Python, PIL, crop problem

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.似乎无法让裁剪正常工作,问题是,它裁剪了一个尺寸正确的区域,但总是从左上角 (0, 0),而不是从我传递的坐标。

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.. :在 PIL 的 image.py 中,我打印了方法 _ImageCrop ..:

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

Values seem to be correct.价值观似乎是正确的。

Input is a JPEG image of size 1600x2390.输入是大小为 1600x2390 的 JPEG 图像。

Python version: 2.5, PIL version: 1.1.6 Python 版本:2.5,PIL 版本:1.1.6

Any suggestions?有什么建议么? Thanks谢谢

Works For Me: Python 2.6.1, PIL 1.1.6, JPEG of size 2020x1338 pixels.为我工作:Python 2.6.1,PIL 1.1.6,大小为 2020x1338 像素的 JPEG。

Are you sure you mean a JPEG of 1600x2390 and not 2390x1600?您确定您的意思是 1600x2390 而不是 2390x1600 的 JPEG 吗? The (1000,400,2000,600) box dimensions are outside the size of a 1600-wide image; (1000,400,2000,600) 框尺寸超出了 1600 宽图像的尺寸; if I try this I get garbage data outside the intersecting area.如果我尝试这个,我会在相交区域之外得到垃圾数据。

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:或者,如果您过去不使用 PNG:

cover.paste(nazv_vert,box_vert_nazv,nazv_vert)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM