Sorl-thumbnail generates a black square instead of an image

I am developing my project inside Vagrant VM, the software version used is:

  • Ubuntu 12.04
  • Django 1.6
  • Sorl Thumbnail 11.12
  • Pillow 2.5.3

I have several images on the path /var/www/django/my_project/media/icons , and I have a model with ImageField pointing to this path.

I also have THUMBNAIL_DEBUG = True in my .py settings

In my template, I use a thumbnail, for example:

 {% 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 several objects with the image, and some others without it, and both show only a black square instead of the image.

  • Does anyone know why this is happening? I use Sorl-Thumbnail in many projects and have never had this problem.

I tried resetting the full database, I used python manage.py thumbnail clear and python manage.py thumbnail cleanup

I installed: libjpeg62 libjpeg62-dev zlib1g-dev

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

  • Am I missing a library or dependency?

I got lost, because, as I said, I worked with Sorl-thumbnail in other projects and never saw anything like it.

Any help would be greatly appreciated


Edit

Here are some images I'm trying to display:

enter image description hereenter image description here

(I have pillow png and jpg libraries)

And this is what I see in all cases:

enter image description here

Edit2

The problem with the background. When I upload a png image with a transparent background, Sorl converts the image to jpg and sets the background to black ...

  • Is there a way to keep the background transparent or avoid conversion?
  • Is it possible to set the background color to white?

I tried:

 THUMBNAIL_COLORSPACE = None THUMBNAIL_PRESERVE_FORMAT = True 

but does not work

+5
source share
2 answers

Finally decided!

To solve the problem with the black background:

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

  • Restart a miniature database using python manage.py thumbnail clear_delete_all
+8
source

The error in this version of scol-thumbnail seems to be due to bad metadata. It is currently fixed in a candidate for release on pypi. Since pip does not install RC by default, you must specify the version to install it. Try:

 pip install sorl-thumbnail==12.1c 

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

0
source

Source: https://habr.com/ru/post/1206264/


All Articles