我正在使用 django。我试图使用 Pythons Image library 将用户上传的图标压缩到更小的尺寸。
以下是我的代码:
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'
有人可以解释为什么会这样吗?