@safe_filter(error_output='<STR_LIT>')<EOL>@register.filter<EOL>def margin(file_, geometry_string):
if not file_ or (sorl_settings.THUMBNAIL_DUMMY or isinstance(file_, DummyImageFile)):<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>margin = [<NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:0>]<EOL>image_file = default.kvstore.get_or_set(ImageFile(file_))<EOL>x, y = parse_geometry(geometry_string, image_file.ratio)<EOL>ex = x - image_file.x<EOL>margin[<NUM_LIT:3>] = ex / <NUM_LIT:2><EOL>margin[<NUM_LIT:1>] = ex / <NUM_LIT:2><EOL>if ex % <NUM_LIT:2>:<EOL><INDENT>margin[<NUM_LIT:1>] += <NUM_LIT:1><EOL><DEDENT>ey = y - image_file.y<EOL>margin[<NUM_LIT:0>] = ey / <NUM_LIT:2><EOL>margin[<NUM_LIT:2>] = ey / <NUM_LIT:2><EOL>if ey % <NUM_LIT:2>:<EOL><INDENT>margin[<NUM_LIT:2>] += <NUM_LIT:1><EOL><DEDENT>return '<STR_LIT:U+0020>'.join(['<STR_LIT>' % n for n in margin])<EOL>
Returns the calculated margin for an image and geometry