Search code examples
pythondjangosorl-thumbnail

Sorl-thumbnail bugs 502 with large image


An error 502 Bad Gateway when I try to show in template large image (more then 2000x2000px) with Sorl-Thumbnail.

No mistake if load page without thumbnail just picture and if less then 20000x2000px

Already tried to change nginx config like this...:

server {
    proxy_connect_timeout       1500;
    proxy_send_timeout          1500;
    proxy_read_timeout          1500;
    send_timeout                1500;
    location / {
        fastcgi_read_timeout 1500;
    }
}

Use regular code in template like

{% thumbnail ph.image "500x500" crop="center" format="PNG" as im %}
<img src="{{ im.url }}"/>
{% endthumbnail %}

Any advise pls?

Just for google search Django Python Sorl-Thumbnail Thumbnail 502 Bad Gateway large image


Solution

  • My friend helped me with this problem. The Pil bugs!

    There is a thing like Engine in Sorl-Thumbnail. Default is Pil

    'sorl.thumbnail.engines.pil_engine.Engine' 
    

    and it bugs with large images. So it is better to use something another like

    Pgmagick, ImageMagick / GraphicsMagick or Wand

    We chosed ImageMagick. In settings.py add

    THUMBNAIL_ENGINE = 'sorl.thumbnail.engines.convert_engine.Engine'
    

    and install it by

    apt-get install imagemagick
    

    And possibly it will be necessary to increate time for image resize processing in gunicorn by this command

    --timeout 600
    

    Also possibly server just does not have enough RAM. I used a server with 512 mb RAM. With simple site. (no wasting RAM...)