<s> """<STR_LIT>""" <EOL> from django import template <EOL> from django . conf import settings <EOL> from django . template import TemplateSyntaxError <EOL> from satchmo_utils . thumbnail . utils import make_thumbnail , get_image_size <EOL> register = template . Library ( ) <EOL> def thumbnail ( url , args = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> kwargs = { } <EOL> if args : <EOL> if '<STR_LIT:U+002C>' not in args : <EOL> args += '<STR_LIT:U+002C>' <EOL> for arg in args . split ( '<STR_LIT:U+002C>' ) : <EOL> arg = arg . strip ( ) <EOL> if arg == '<STR_LIT>' : continue <EOL> kw , val = arg . split ( '<STR_LIT:=>' , <NUM_LIT:1> ) <EOL> kw = kw . lower ( ) . encode ( '<STR_LIT:ascii>' ) <EOL> try : <EOL> val = int ( val ) <EOL> except ValueError : <EOL> raise template . TemplateSyntaxError , "<STR_LIT>" % ( kw , val ) <EOL> kwargs [ kw ] = val <EOL> if ( '<STR_LIT:width>' not in kwargs ) and ( '<STR_LIT>' not in kwargs ) : <EOL> raise template . TemplateSyntaxError , "<STR_LIT>" <EOL> ret = make_thumbnail ( url , ** kwargs ) <EOL> if ret is None : <EOL> ret = url <EOL> if not ret . startswith ( settings . MEDIA_URL ) : <EOL> ret = settings . MEDIA_URL + ret <EOL> return ret <EOL> register . filter ( '<STR_LIT>' , thumbnail ) <EOL> def image_width ( url ) : <EOL> """<STR_LIT>""" <EOL> width , height = get_image_size ( url ) <EOL> return width <EOL> register . filter ( '<STR_LIT>' , image_width ) <EOL> def image_height ( url ) : <EOL> """<STR_LIT>""" <EOL> width , height = get_image_size ( url ) <EOL> return height <EOL> register . filter ( '<STR_LIT>' , image_height ) </s>
