migajek
migajek

Reputation: 8614

sorl-thumbnail - resize only if image is bigger then given dimmension

How can I prevent sorl-thumbnail from scaling up images which are smaller than desired thumbnail?

When scaling using {% thumbnail %} tag, the image is always scaled to desired dimmensions, while I want it to scale only images which are bigger than that.

Upvotes: 0

Views: 1713

Answers (2)

Artur Barseghyan
Artur Barseghyan

Reputation: 14202

Why not use the sorl-thumbnail built-in upscale filter for that?

{% thumbnail image "1500x1500" upscale=False as thumb %}

Default value for upscale is True. Set it to False to get the desired behaviour.

Upvotes: 3

Micah Carrick
Micah Carrick

Reputation: 10197

If you using ImageField I believe you can check the width/height first.

{% if image.width > 100 %}
    {% thumbnail image 100x100 as thumb %}
        <img src="{{ thumb.url }}"/>
    {% endthumbnail %}
{% else %}
    <img src="{{ image.url }}"/>
{% endif %}

Upvotes: 3

Related Questions