问题描述
我正在尝试裁切非常高分辨率的图像并保存结果以确保其完成.但是,无论如何使用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库裁剪和保存图像时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!