AlvaroAV
AlvaroAV

Reputation: 10553

Sorl-thumbnail generates black square instead of image

I'm developing my project inside a Vagrant VM, the software version I'm using is:

I have some pictures in the path /var/www/django/my_project/media/icons and I have a model with an ImageField pointing to that path.

I have also THUMBNAIL_DEBUG = True in my settings.py

In my template I use thumbnail like:

{% thumbnail category.image "20" as im %}
    <img src="{{ im.url }}"></img>
{% empty %}
    {% thumbnail "png/no_image.png" "20" as im %}  # Thumbnail add the rest of the path to media
        <img id="no_image" alt="" src="{{ im.url }}" />
    {% endthumbnail%}
{% endthumbnail %}

There are some objects with image and some others without it and both shows just a black square instead of the image.

I've tried to reset the full database, I used python manage.py thumbnail clear and python manage.py thumbnail cleanup

I've installed: libjpeg62 libjpeg62-dev zlib1g-dev

no_image.png is an image (red cross) not an empty image

I'm lost because as I said I've worked with Sorl-thumbnail in other projects, and never saw anything like this.

Any help would be much appreciated


Edit

Here are some images I'm trying to display:

enter image description here enter image description here

( I have png and jpg libraries working on Pillow )

And this is what I see in all cases:

enter image description here

Edit2

The problem is with the background. When I upload a png image with transparent background sorl converts the image to jpg and set the background to black...

I tried with:

THUMBNAIL_COLORSPACE = None
THUMBNAIL_PRESERVE_FORMAT = True

but didn't work

Upvotes: 8

Views: 2204

Answers (2)

AlvaroAV
AlvaroAV

Reputation: 10553

Finally solved !

To solve the issue with the black background:

  • I updated sorl-thumbnail to 12.2
  • Added this 2 lines to settings.py:
    • THUMBNAIL_COLORSPACE = None
    • THUMBNAIL_PRESERVE_FORMAT = True

  • Restart thumbnail database with python manage.py thumbnail clear_delete_all

Upvotes: 11

relekang
relekang

Reputation: 1884

It seems like a bug in that version of sorl-thumbnail related to bad meta-data. It is currently fixed in the release candidate currently on pypi. Since pip does not install RC by default you have to specify the version to install it. Try:

pip install sorl-thumbnail==12.1c

I tried it out with the python logo and it worked fine for me with 12.1c

Upvotes: 0

Related Questions