Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Sorl thumbs for the lazy
Usage: {% thumb p.image "noimage.png" %}
from django import template
register = template.Library()
def thumb(img_obj, no_image="noimage.png", dim="100x100", no_image_dim="100px", ori="600"):
return { 'img_obj': img_obj,
'dim': dim,
'ori':ori, }
# includes/thumb.html
{% load thumbnail %}
{% thumbnail img_obj dim crop="80% top" as im %}
{% thumbnail img_obj ori as ori %}
<a class="product_image" href="{{ ori.url }}" title="{{|title }}">
<img src="{{ im.url }}" style="width:{{ im.width }};height:{{ im.height }};">
{% endthumbnail %}
{% empty %}
<img src="{{ no_image }}" style="width:{{ no_image_dim }};height:{{ no_image_dim }};">
{% endthumbnail %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.