【发布时间】:2014-05-03 13:38:34
【问题描述】:
我在我的网站上发布了一张 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)
回溯是:
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(32bit)、python3、pillow2.4.0,并且我已经安装了 libjpeg8-dev、python3-dev python3-imaging 并重新安装了枕头(在 virtualenv 中),但没有修复
【问题讨论】:
-
根据您的特定 JPEG 文件使用的功能,您似乎需要升级或降级
libjpeg。 This answer 表示 降级 到libjpeg6b 可能会有所帮助(并再次重新安装PIL)。您还可以尝试找出您的 JPEG 文件使用的 features,例如与 ImageMagick 的identify. -
已经尝试过,但没有任何改变...
标签: django python-3.x pillow