我想用PIL把一堆图片粘贴在一起。由于某些原因,当我运行blank.paste(img,(i*128,j*128))行时,我得到以下错误:ValueError: cannot determine region size; use 4-item box
我试着弄乱它,并使用一个有4个元素的元组,就像它说的那样(例如。(128,128,128,128))但是它给出了这个错误:SystemError: new style getargs format but argument is not a tuple
每个图像的大小为128x,命名风格为"x_y.png“,其中x和y的取值范围为0到39。我的代码如下。
from PIL import Image
loc = 'top right/'
blank = Image.new("RGB", (6000,6000), "white")
for x in range(40):
for y in reversed(range(40)):
file = str(x)+'_'+str(y)+'.png'
img = open(loc+file)
blank.paste(img,(x*128,y*128))
blank.save('top right.png')我怎么才能让它工作呢?
发布于 2013-10-21 13:09:32
您没有正确加载图像。内置函数open只是打开一个新的文件描述符。要使用PIL加载图像,请改用Image.open:
from PIL import Image
im = Image.open("bride.jpg") # open the file and "load" the image in one statement如果你有理由使用内置的open,那么可以这样做:
fin = open("bride.jpg") # open the file
img = Image.open(fin) # "load" the image from the opened file使用PIL,“加载”图像意味着读取图像标题。PIL是惰性的,所以它直到需要时才加载实际的图像数据。
另外,考虑使用os.path.join而不是字符串连接。
发布于 2017-04-11 19:53:29
这对我来说很有效,我用的是Odoo v9,我用的是Pillow4.0。
我在我的服务器上用ubuntu实现了这一点:
# pip uninstall pillow
# pip install Pillow==3.4.2
# /etc/init.d/odoo restart发布于 2018-10-31 22:52:55
对我来说,上面的方法不起作用。
在检查了image.py之后,我发现image.paste(color)还需要一个像image.paste(color, mask=original)这样的参数。它对我来说效果很好,只需将其更改为:
image.paste(color, box=(0, 0) + original.size)https://stackoverflow.com/questions/19486337
复制相似问题