got OSError when use pillow to deal with my jpg image

十年热恋 提交于 2019-12-11 03:14:36

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/23445171/got-oserror-when-use-pillow-to-deal-with-my-jpg-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!