sorl thumbnail

205 views
Skip to first unread message

Greg Donald

unread,
Jun 10, 2011, 12:59:37 PM6/10/11
to django...@googlegroups.com
Sorry if this is off-topic, I was unable to find a user group for my
exact issue.

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/sorl_thumbnail-11.05.2-py2.6.egg/sorl/thumbnail/templatetags/thumbnail.py",
line 45, in render
return self._render(context)

File "/usr/local/lib/python2.6/dist-packages/sorl_thumbnail-11.05.2-py2.6.egg/sorl/thumbnail/templatetags/thumbnail.py",
line 97, in _render
file_, geometry, **options

File "/usr/local/lib/python2.6/dist-packages/sorl_thumbnail-11.05.2-py2.6.egg/sorl/thumbnail/base.py",
line 49, in get_thumbnail
thumbnail)

File "/usr/local/lib/python2.6/dist-packages/sorl_thumbnail-11.05.2-py2.6.egg/sorl/thumbnail/base.py",
line 74, in _create_thumbnail
image = default.engine.create(source_image, geometry, options)

File "/usr/local/lib/python2.6/dist-packages/sorl_thumbnail-11.05.2-py2.6.egg/sorl/thumbnail/engines/base.py",
line 14, in create
image = self.colorspace(image, geometry, options)

File "/usr/local/lib/python2.6/dist-packages/sorl_thumbnail-11.05.2-py2.6.egg/sorl/thumbnail/engines/base.py",
line 24, in colorspace
return self._colorspace(image, colorspace)

File "/usr/local/lib/python2.6/dist-packages/sorl_thumbnail-11.05.2-py2.6.egg/sorl/thumbnail/engines/pil_engine.py",
line 33, in _colorspace
return image.convert('RGB')

File "/usr/local/lib/python2.6/dist-packages/PIL/Image.py", line 679,
in convert
self.load()

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. Stuck.


Thanks,


--
Greg Donald
destiney.com | gregdonald.com

Greg Donald

unread,
Jun 10, 2011, 1:11:54 PM6/10/11
to django...@googlegroups.com
On Fri, Jun 10, 2011 at 11:59 AM, Greg Donald <gdo...@gmail.com> wrote:
>  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


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.

Nan

unread,
Jun 10, 2011, 1:41:48 PM6/10/11
to Django users

I encountered that error at one point when upgrading Sorl Thumbnail
versions. Can't remember exactly how I worked around it, but it had
something to do with clearing out caches. There are data caches that
you can clear with Sorl's custom management commands and disk caches
that you can delete.

Also make sure that you're passing valid parameters -- i.e. that
up.image is an ImageField.


On Jun 10, 1:11 pm, Greg Donald <gdon...@gmail.com> wrote:

Greg Donald

unread,
Jun 10, 2011, 1:52:00 PM6/10/11
to django...@googlegroups.com
On Fri, Jun 10, 2011 at 12:41 PM, Nan <ring...@gmail.com> wrote:
> I encountered that error at one point when upgrading Sorl Thumbnail
> versions.  Can't remember exactly how I worked around it, but it had
> something to do with clearing out caches.

My cache is clean, this is a new app. My key/value table is empty,
and my cache directory is empty and writable.

> There are data caches that
> you can clear with Sorl's custom management commands and disk caches
> that you can delete.
>
> Also make sure that you're passing valid parameters -- i.e. that
> up.image is an ImageField.

It is, it's a sorl thumbnail ImageField to be exact.

Blue Cuenca

unread,
Jun 11, 2011, 2:50:56 AM6/11/11
to django...@googlegroups.com
Is your cache, readable and writable to other groups/users as well?


--
Your eyes are weary from staring at the CRT. You feel sleepy. Notice
how restful it is to watch the cursor blink. Close your eyes. The
opinions stated above are yours. You cannot imagine why you ever felt
otherwise.

Greg Donald

unread,
Jun 11, 2011, 10:33:05 AM6/11/11
to django...@googlegroups.com
On Sat, Jun 11, 2011 at 1:50 AM, Blue Cuenca <azu...@gmail.com> wrote:
> Is your cache, readable and writable to other groups/users as well?

Yes, as I stated in a previous post, my entire application is chown'd
to my web server user and group 'www-data'. Every directory down to
and including my cache directory is fully readable and writable by
all.

It doesn't say it's a permissions error is the thing, just that the
stream is broken. Meanwhile I can create a thumbnail easily using
`manage.py shell`. From that I know sorl thumbnail has all the
required libraries installed and my uploaded image is not corrupt.
The only thing left is permissions, and they are as open as they can
be.

Greg Donald

unread,
Jun 15, 2011, 1:39:02 PM6/15/11
to django...@googlegroups.com

So what does one use for thumbnails when sorl thumbnail works great in development but fails on two different production servers?


Kenneth Gonsalves

unread,
Jun 15, 2011, 9:34:25 PM6/15/11
to django...@googlegroups.com

easy-thumbnail
--
regards
KG
http://lawgon.livejournal.com
Coimbatore LUG rox
http://ilugcbe.techstud.org/

Reply all
Reply to author
Forward
0 new messages