async def preview_template(t, zoom, fetch): """Get a preview image from a template. Arguments: t - A template object. zoom - The factor to zoom by, integer. fetch - A fetching function. Returns: The preview, as a PIL Image object. """ log.info("(X:{0} | Y:{1} | Dim:{2}x{3} | Zoom:{4})".format(t.x, t.y, t.width, t.height, zoom)) dim = Coords(t.width, t.height) if zoom < -1: dim *= abs(zoom) c = Coords(*t.center()) preview_img = await fetch(c.x - dim.x // 2, c.y - dim.y // 2, *dim) if zoom > 1: preview_img = preview_img.resize(tuple(zoom * x for x in preview_img.size), Image.NEAREST) tlp = Coords(preview_img.width // 2 - config.PREVIEW_W // 2, preview_img.height // 2 - config.PREVIEW_H // 2) preview_img = preview_img.crop((*tlp, tlp.x + config.PREVIEW_W, tlp.y + config.PREVIEW_H)) return preview_img
async def preview(x, y, zoom, fetch): """Get a preview image from coordinates. Arguments: x - The x coord, integer. y - The y coord, integer. zoom - The factor to zoom by, integer. fetch - A fetching function. Returns: The preview, as a PIL Image object. """ log.info("(X:{0} | Y:{1} | Zoom:{2})".format(x, y, zoom)) dim = Coords(config.PREVIEW_W, config.PREVIEW_H) if zoom < -1: dim *= abs(zoom) preview_img = await fetch(x - dim.x // 2, y - dim.y // 2, *dim) if zoom > 1: preview_img = preview_img.resize(tuple(zoom * x for x in preview_img.size), Image.NEAREST) tlp = Coords(preview_img.width // 2 - config.PREVIEW_W // 2, preview_img.height // 2 - config.PREVIEW_H // 2) preview_img = preview_img.crop((*tlp, tlp.x + config.PREVIEW_W, tlp.y + config.PREVIEW_H)) if config.INVERT: preview_img = ImageOps.invert(preview_img) return preview_img
async def preview_template(t, zoom, fetch): log.info("(X:{0} | Y:{1} | Dim:{2}x{3} | Zoom:{4})".format(t.x, t.y, t.width, t.height, zoom)) dim = Coords(t.width, t.height) if zoom < -1: dim *= abs(zoom) c = Coords(*t.center()) preview_img = await fetch(c.x - dim.x // 2, c.y - dim.y // 2, *dim) if zoom > 1: preview_img = preview_img.resize(tuple(zoom * x for x in preview_img.size), Image.NEAREST) tlp = Coords(preview_img.width // 2 - config.PREVIEW_W // 2, preview_img.height // 2 - config.PREVIEW_H // 2) preview_img = preview_img.crop((*tlp, tlp.x + config.PREVIEW_W, tlp.y + config.PREVIEW_H)) return preview_img
async def preview(x, y, zoom, fetch): log.info("(X:{0} | Y:{1} | Zoom:{2})".format(x, y, zoom)) dim = Coords(config.PREVIEW_W, config.PREVIEW_H) if zoom < -1: dim *= abs(zoom) preview_img = await fetch(x - dim.x // 2, y - dim.y // 2, *dim) if zoom > 1: preview_img = preview_img.resize(tuple(zoom * x for x in preview_img.size), Image.NEAREST) tlp = Coords(preview_img.width // 2 - config.PREVIEW_W // 2, preview_img.height // 2 - config.PREVIEW_H // 2) preview_img = preview_img.crop((*tlp, tlp.x + config.PREVIEW_W, tlp.y + config.PREVIEW_H)) if config.INVERT: preview_img = ImageOps.invert(preview_img) return preview_img