Sorl thumbs for the lazy

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
'''
Sorl thumbs for the lazy.

Usage: {% thumb p.image "noimage.png" %}

[Fork it here.](https://gist.github.com/985439)
'''

# tags.py
from django import template
register = template.Library()

@register.inclusion_tag("includes/thumb.html")
def thumb(img_obj, no_image="noimage.png", dim="100x100", no_image_dim="100px", ori="600"):
	return { 'img_obj': img_obj,
	         'no_image':no_image,
	         'dim': dim,
	         'no_image_dim':no_image_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="{{ img_obj|title }}">
			<img src="{{ im.url }}" style="width:{{ im.width }};height:{{ im.height }};">
		</a>
	{% endthumbnail %}
{% empty %}
	<img src="{{ no_image }}" style="width:{{ no_image_dim }};height:{{ no_image_dim }};">
{% endthumbnail %}

More like this

  1. Letterbox for sorl-thumbnail by Mogga 4 years, 1 month ago
  2. Serialize JSON object into a model object and retrieve a python dictionary on load by cstrap 2 years, 6 months ago
  3. sorl.thumbnail processor: white background by izibi 4 years, 9 months ago
  4. Drupal password hasher for migration by dgrtwo 1 year, 1 month ago
  5. Sorl Thumbnail + Amazon S3 by skoczen 3 years, 11 months ago

Comments

(Forgotten your password?)