尝试调用save函数会导致TypeError。附注: qrcode需要将PIL导入为PilImage。
值得一提的是,在使用Python图像库时,我没有遇到这个错误。只有在切换到枕头后才会发生这种情况。
from qrcode import *
import PIL as PilImage
from PIL import Image
import qrcode
qr = qrcode.QRCode (
version = 1,
error_correction = qrcode.constants.ERROR_CORRECT_L,
box_size = 10,
border = 2
)
qr.add_data('Hello World')
qr.make(fit=True)
img = qr.make_image()
img.format = 'PNG'
img.save('test.png')
Traceback (most recent call last):
File "<pyshell#70>", line 1, in <module>
img.save('test.png')
File "build\bdist.win32\egg\qrcode\image\pil.py", line 29, in save
self._img.save(stream, kind)
File "C:\Python27\lib\site-packages\PIL\Image.py", line 1467, in save
save_handler(self, fp, filename)
File "C:\Python27\lib\site-packages\PIL\PngImagePlugin.py", line 605, in _save
ImageFile._save(im, _idat(fp, chunk), [("zip", (0,0)+im.size, 0, rawmode)])
File "C:\Python27\lib\site-packages\PIL\ImageFile.py", line 452, in _save
e = Image._getencoder(im.mode, e, a, im.encoderconfig)
File "C:\Python27\lib\site-packages\PIL\Image.py", line 395, in _getencoder
return encoder(mode, *args + extra)
TypeError: function takes at most 4 arguments (6 given)发布于 2014-04-16 01:03:29
作为最后的努力,我重新安装了Pillow模块。这奇迹般地解决了我的问题,img.save()现在完全按照预期工作了。我不确定是怎么回事,但一定是在初始安装过程中出了问题。不过,还是要感谢你的帮助。这段经历简直就是地狱。如果你想知道这个冲突是怎么回事,这里是我的git存储库:https://github.com/NamesJ/qr-tickets
发布于 2014-04-14 01:17:16
会不会是img.size()返回了长度为4的tupe?
在这种情况下,您应该让它返回一个长度为2的元组,如下所示:
size = img.size
img.size = size[0], size[1]
img.save('test.png')试一试,然后汇报一下。可能还有其他的可能性。
https://stackoverflow.com/questions/23044470
复制相似问题