From 6b69da393cbc14aaed80eb193005cd34e6add1b6 Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Wed, 17 Oct 2018 19:25:29 +0200 Subject: [PATCH] Convert into server application. --- handler.py | 18 ++++++++++++++---- krpanosteal/__init__.py | 10 ++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/handler.py b/handler.py index 9d948a9..4f4b970 100755 --- a/handler.py +++ b/handler.py @@ -2,6 +2,7 @@ import re import importlib +import argparse regs = { "\d/\d/\d_\d\.jpg": "krpanosteal", @@ -25,7 +26,16 @@ def parse_url(url): return importlib.import_module(selected).process_url if __name__ == "__main__": - url = input("Please input the URL of an image. ") - handler = parse_url(url) - image = handler(url) - image.save("out.png") + parser = argparse.ArgumentParser() + parser.add_argument('url', help='URL to process') + parser.add_argument('--title', help='title to be used for the file name') + parser.add_argument("--rotation", nargs=3, type=int, help="rotation on x/y/z axes", metavar=("x","y","z")) + parser.add_argument("--resolution", type=int, nargs=2, metavar=("w","h")) + parser.add_argument("--output") + + args = parser.parse_args() + + handler = parse_url(args.url) + image = handler(args.url, args.rotation or [0,0,0], args.resolution or [3840, 1920]) + + image.save(args.output + "/" + args.title + ".png") diff --git a/krpanosteal/__init__.py b/krpanosteal/__init__.py index 2fc9c52..dd3a7d3 100644 --- a/krpanosteal/__init__.py +++ b/krpanosteal/__init__.py @@ -336,7 +336,7 @@ def krpano_make_tiles(url): raise ValueError("%s does not seem to be a valid krpano URL." % url) -def krpano_to_equirectangular(url, blender=True): +def krpano_to_equirectangular(url, rotation=[0,0,0], resolution=[0,0]): ''' Takes the URL of any image in a krpano panorama and returns a finished stitched image. @@ -346,9 +346,11 @@ def krpano_to_equirectangular(url, blender=True): ''' stitched = krpano_make_tiles(url) - function = tiles_to_equirectangular_blender if blender \ - else tiles_to_equirectangular - return function(*stitched) + function = tiles_to_equirectangular_blender + + rx, ry, rz = rotation + width, height = resolution + return function(*stitched, rx=rx, ry=ry, rz=rz, width=width, height=height) process_url = krpano_to_equirectangular