stackniu
stackniu

Reputation: 31

got OSError when use pillow to deal with my jpg image

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

Upvotes: 2

Views: 1216

Answers (1)

Chris Montanaro
Chris Montanaro

Reputation: 18192

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

Upvotes: 2

Related Questions