我将jpg图片发布到我的网站(在django上构建),但是当我使用枕头来处理它时,我在“读取图像文件时在url XXXX / XXX损坏数据流时出现了OSError”
在服务器中运行代码时会发生这种情况:
if request.FILES:
img = request.FILES['img']
ftype = img.content_type.split('/')[1]
image = Image.open(img)
imagefit = ImageOps.fit(image, (200, 200), Image.ANTIALIAS)
fpath = MEDIA_ROOT+'avatar/'+user.username+'.'+ftype
getpath = 'avatar/'+user.username+'.'+ftype
imagefit.save(fpath,ftype)
和Traceback是:
view:
imagefit = ImageOps.fit(image, (200, 200), Image.ANTIALIAS)
/PIL/ImageOps.py in fit:
(leftSide, topSide, leftSide + cropWidth, topSide + cropHeight)
/PIL/Image.py in crop:
self.load()
/PIL/ImageFile.py in load:
raise_ioerror(e)
/PIL/ImageFile.py in raise_ioerror:
raise IOError(message + " when reading image file")
message 'broken data stream'
error -2
img <InMemoryUploadedFile: 169902.jpg (image/jpeg)>
ftype 'jpeg'
image <PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=1650x2550 at 0xB5CCBECC>
我正在使用ubuntu 13.10(32位),python3,pillow2.4.0,我已经安装了libjpeg8-dev,python3-dev python3-imaging和重新安装枕头(在virtualenv中),但没有修复
答案 0 :(得分:2)
尝试安装libjpeg,然后重新安装枕头:
sudo apt-get install libjpeg8 libjpeg8-dev
pip install --force-reinstall Pillow
如果版本不可用,请尝试以下方法查找可用的版本:
apt-cache search libjpeg