我正在使用django。我试图使用Pythons图像库将用户上传的图标压缩为更小的尺寸。无效的文件名或模式'wb'
以下是我的代码:
def resizeImage(icon,ext):
path= os.path.join(settings.SITE_ROOT,'karnadash/static/tempfiles/temp'+ext)
destination = open(path,'wb+')
for chunk in icon.chunks():
destination.write(chunk)
destination.close()
image = Image.open(path)
image= image.resize((50, 50), Image.ANTIALIAS)
image.save(path)
return image
问题是我得到一个内部服务器错误。堆栈跟踪的最后一部分如下:
line 31, in resizeImage
image.save(path)
File "C:\Python27\lib\site-packages\PIL\Image.py", line 1446, in save
fp = builtins.open(fp, "wb+")
IOError: [Errno 22] invalid mode ('wb') or filename: 'C:/Users/Silent/Documents/Python/karnadash/karnadash/static/tempfiles/temp.jpg'
任何人都可以请解释为什么会发生这种情况吗?
IOError消息中是否真的有换行符?请不要重新格式化这些行。 –
不,我从命令提示符复制它,所以也许这就是为什么。 – Sohaib
对,Windows cmd确实可以复制和粘贴。 –