Python、PIL、作物问题

发布于 2024-07-14 21:08:32 字数 422 浏览 10 评论 0原文

似乎无法使裁剪正常工作,问题是,它裁剪了尺寸正确的区域,但总是从左上角 (0, 0),而不是从我传递的坐标开始。

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

在 PIL 的 image.py 中,方法 _ImageCrop 我已经打印出来了..:

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

值似乎是正确的。

输入是尺寸为 1600x2390 的 JPEG 图像。

Python版本:2.5, PIL 版本:1.1.6

有什么建议吗? 谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岁月无声 2024-07-21 21:08:32

适用于我:Python 2.6.1、PIL 1.1.6、尺寸为 2020x1338 像素的 JPEG。

您确定您指的是 1600x2390 而不是 2390x1600 的 JPEG 吗? (1000,400,2000,600)框尺寸超出了1600宽图像的尺寸; 如果我尝试这样做,我会在相交区域之外得到垃圾数据。

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.

失退 2024-07-21 21:08:32

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)

或者如果你过去不喜欢用PNG:

cover.paste(nazv_vert,box_vert_nazv,nazv_vert)

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文