【发布时间】:2013-07-04 10:29:08
【问题描述】:
我正在使用 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'
谁能解释一下为什么会这样?
【问题讨论】:
-
IOError消息中真的有换行符吗?请不要重新格式化这些行。 -
不,我是从命令提示符复制的,所以也许这就是原因。
-
对,Windows cmd 确实不适合复制和粘贴。
-
无论如何,人们都会看到这个问题。
标签: python django python-imaging-library