简体   繁体   中英

(Django and PIL) encoder error -2 when writing image file

I'm new in Django and currently I am working on a my first project. For the thumbnails I'm using sorl-thumbnails, but a strange error piss me off and cannot figure out from where is come from.

That what I try to do is to re-size a image and crop 165x165 with canvas. After that I'm sending the image to the server and save it with PIL. Everything working good in 90% of cases, but some time I receive a error with the following text - "encoder error -2 when writing image file" and "Suspension not allowed here" in the console. The exception is raised on the follow row:

{% thumbnail request.user.artist.get_avatar "50x50" crop="center" as im %}

The strange here is that when I change it from "50x50" to "55x55". Everything start working.

The pictures are always with the same size (165x165). I have checked in the media folder and the image is saved properly. The python version which I use is python 3.3.2 ,the version for Pillow is 2.2.2 and Django 1.6. Аny help would be useful.

Thanks in advance.

Got the same error when using it with sorl-thumbnail. After long time spend on Google, i have came with this simple solution. Actually the error comes from PIL(python-pil) . But for Ubuntu users, "pip install PIL" is no longer in service :(. But the coolest thing is we can get rid of this error by simple package python-imaging.

sudo apt-get install python-imaging

hopes that you already installed python-pil and other dependencies mentioned in the sorl-thumbnail tutorial,

for sorl-thumbnail

sudo apt-get install libjpeg62 libjpeg62-dev zlib1g-dev

for python-pil

sudo apt-get install python-pil python-pil-doc python-pil-dbg

请在这里查看我的答案https://stackoverflow.com/a/41018959/1176671我在我的Django项目中这样做,所以希望它也可以帮助你使用Django。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM