1 from django import template
2 from django.conf import settings
3 from generic import helpers
6 register = template.Library()
8 def thumbnail(image_url, args=''):
14 for arg in args.split(','):
17 (kw,val) = arg.split('=', 1)
19 options[kw] = int(val)
25 if "height" in options or "width" in options:
26 if "width" in options and "height" in options:
27 return helpers.make_thumbnail(image_url[len(settings.MEDIA_URL):], width=options["width"], height=options["height"])
28 elif "width" in options:
29 return helpers.make_thumbnail(image_url[len(settings.MEDIA_URL):], width=options["width"])
31 return helpers.make_thumbnail(image_url[len(settings.MEDIA_URL):], height=options["height"])
35 return "%s" %(image_url)
37 register.filter(thumbnail)