def image_resolver(node): fname = find_resource_path(str(node.getAttribute('file')), RESOURCE_DIRS) from google.appengine.api.images import Image from template2pdf.t2p.utils import as_pt img = Image(file(fname, 'rb').read()) sx, sy = img.width, img.height args = {} for tag in ('width', 'height', 'x', 'y'): if node.hasAttribute(tag): args[tag] = as_pt(node.getAttribute(tag)) if ('width' in args) and (not 'height' in args): args['height'] = sy * args['width'] / sx elif ('height' in args) and (not 'width' in args): args['width'] = sx * args['height'] / sy elif ('width' in args) and ('height' in args): if (float(args['width'])/args['height'])>(float(sx)>sy): args['width'] = sx * args['height'] / sy else: args['height'] = sy * args['width'] / sx return fname, args
def image_resolver(node): fname = find_resource_path(str(node.getAttribute('file')), RESOURCE_DIRS) from google.appengine.api.images import Image from template2pdf.t2p.utils import as_pt img = Image(file(fname, 'rb').read()) sx, sy = img.width, img.height args = {} for tag in ('width', 'height', 'x', 'y'): if node.hasAttribute(tag): args[tag] = as_pt(node.getAttribute(tag)) if ('width' in args) and (not 'height' in args): args['height'] = sy * args['width'] / sx elif ('height' in args) and (not 'width' in args): args['width'] = sx * args['height'] / sy elif ('width' in args) and ('height' in args): if (float(args['width']) / args['height']) > (float(sx) > sy): args['width'] = sx * args['height'] / sy else: args['height'] = sy * args['width'] / sx return fname, args
def pdf_resource(arg): if arg.startswith('/'): return arg.lstrip('/') else: return find_resource_path(arg, RESOURCE_DIRS)