【问题标题】:got OSError when use pillow to deal with my jpg image使用枕头处理我的 jpg 图像时出现 OSError
【发布时间】: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 文件使用的功能,您似乎需要升级或降级 libjpegThis answer 表示 降级libjpeg 6b 可能会有所帮助(并再次重新安装 PIL)。您还可以尝试找出您的 JPEG 文件使用的 features,例如与 ImageMagick 的 identify.
  • 已经尝试过,但没有任何改变...

标签: django python-3.x pillow


【解决方案1】:

尝试安装 libjpeg 然后重新安装枕头:

sudo apt-get install libjpeg8 libjpeg8-dev

pip install --force-reinstall Pillow

如果版本不可用,请尝试以下操作以查找可用的版本:

apt-cache search libjpeg

【讨论】:

  • 无法找到软件包 libjpeg
猜你喜欢
  • 1970-01-01
  • 2018-03-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多