I’m using sorl thumbnail with Django. On my local setup it works fine, but in production the thumbnails are not made.
My code looks like this:
{% load thumbnail %}
{% thumbnail up.image "32x32" crop="center" as im %}
<img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}">
{% empty %}
<img src="{{ MEDIA_URL }}/images/missing_small.png" alt="" title="" />
{% endthumbnail %}
I enabled logging and the trace looks like this:
Traceback (most recent call last):
[...]
File "/usr/local/lib/python2.6/dist-packages/PIL/ImageFile.py", line
215, in load
raise_ioerror(e)
File "/usr/local/lib/python2.6/dist-packages/PIL/ImageFile.py", line
52, in raise_ioerror
raise IOError(message + " when reading image file")
IOError: broken data stream when reading image file
The error isn’t very helpful since the file is there and is readable by all. I’m not sure how to get a more explicit error, or what to try and fix.
And then more baffling is the fact that it works using manage.py shell
In [1]: from sorl.thumbnail import get_thumbnail
In [2]: im = get_thumbnail('/myproject/static/images/user_profiles/1/11-20-2010-2_5.jpg',
'32x32', crop='center' )
In [3]: im
Out[3]: <sorl.thumbnail.images.ImageFile object at 0x29fe090>
In [4]: im.url
Out[4]: 'http://example.com/cache/ff/31/ff318b4a995ff345d1d48e79b67ec62b.jpg'
It made the thumbnail, just won’t make one via the template code.
Anyone?
Tried everything. Ended up solving itself with a newer Linux distro. Wouldn’t work on Ubuntu 10.04 but after that it works fine for me, 11.04, 11.10, etc.