当使用枕头处理我的jpg图像时,得到OSError [英] got OSError when use pillow to deal with my jpg image

查看:302
本文介绍了当使用枕头处理我的jpg图像时,得到OSError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发布了一个jpg图片到我的网站(建立在django),但是当我使用枕头来处理它时,我收到在读取图像文件时的URL XXXX / XXX破坏的数据流的OSError$ / b
$ b

在服务器中运行代码时会发生:

  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适合:
(leftSide,topSide,leftSide + cropWidth,topSide + cropHeight)
/PIL/Image.py在crop:
self.load()
/PIL/ImageFile.py加载:
raise_ioerror(e)
/PIL/ImageFile.py在raise_ioerror中:
raise IOError(消息+读取图像文件时)

消息破碎的数据流
错误-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-成像和重新安装枕头(在virtualenv中),但不是固定的

解决方案

libjpeg然后重新安装枕头:

  sudo apt-get install libjpeg8 libjpeg8-dev 

pip install - - 重新安装枕头

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

  apt-cache search libjpeg 


I'm post a jpg picture to my website (build on django), but I got "OSError at url XXXX/XXX broken data stream when reading image file" when I use pillow to deal with it

it happens when run the code in server :

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)

and the Traceback is:

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>

I'm using ubuntu 13.10(32bit), python3, pillow2.4.0, and I've install libjpeg8-dev, python3-dev python3-imaging and re-install pillow (in virtualenv), but not fixed

解决方案

Try installing libjpeg and then reinstall pillow:

sudo apt-get install libjpeg8 libjpeg8-dev

pip install --force-reinstall Pillow

If the version is unavailable try the following to find what versions are available:

apt-cache search libjpeg

这篇关于当使用枕头处理我的jpg图像时,得到OSError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆