使用python PIL库裁剪和保存图像时出现问题 [英] Trouble using python PIL library to crop and save image

查看:229
本文介绍了使用python PIL库裁剪和保存图像时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试裁切非常高分辨率的图像并保存结果以确保其完成.但是,无论如何使用save方法,我都会不断收到以下错误消息:SystemError: tile cannot extend outside image

Im attempting to crop a pretty high res image and save the result to make sure its completed. However I keep getting the following error regardless of how I use the save method: SystemError: tile cannot extend outside image

from PIL import Image

# size is width/height
img = Image.open('0_388_image1.jpeg')
box = (2407, 804, 71, 796)
area = img.crop(box)

area.save('cropped_0_388_image1', 'jpeg')
output.close()

推荐答案

该框是(左,上,右,下),所以也许您是说(2407,804,2407 + 71,804 + 796)?

The box is (left, upper, right, lower) so maybe you meant (2407, 804, 2407+71, 804+796)?

编辑:所有四个坐标均从上/左角开始测量,并描述了从该角到左边缘,上边缘,右边缘和下边缘的距离.

Edit: All four coordinates are measured from the top/left corner, and describe the distance from that corner to the left edge, top edge, right edge and bottom edge.

您的代码应如下所示,以从位置2407,804获得300x200的区域:

Your code should look like this, to get a 300x200 area from position 2407,804:

left = 2407
top = 804
width = 300
height = 200
box = (left, top, left+width, top+height)
area = img.crop(box)

这篇关于使用python PIL库裁剪和保存图像时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆