use*_*745 8 python python-imaging-library
我想将一堆图像与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')
Run Code Online (Sandbox Code Playgroud)
我怎样才能让它发挥作用?
您没有正确加载图像。内置函数open只会打开一个新的文件描述符。要使用PIL加载图像,请Image.open改用:
from PIL import Image
im = Image.open("bride.jpg") # open the file and "load" the image in one statement
Run Code Online (Sandbox Code Playgroud)
如果您有理由使用内置open,请执行以下操作:
fin = open("bride.jpg") # open the file
img = Image.open(fin) # "load" the image from the opened file
Run Code Online (Sandbox Code Playgroud)
使用PIL,“加载”图像意味着读取图像标题。PIL是惰性的,因此它直到需要时才加载实际的图像数据。
另外,考虑使用os.path.join代替字符串串联。
这对我有用,我使用的是Odoo v9,我的枕头为4.0。
我使用ubuntu在服务器中完成了它:
# pip uninstall pillow
# pip install Pillow==3.4.2
# /etc/init.d/odoo restart
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12570 次 |
| 最近记录: |