From d09a64ce01b37fa67c905df1a28f81f91d59e065 Mon Sep 17 00:00:00 2001 From: jaseg Date: Sat, 6 Apr 2013 16:26:13 +0200 Subject: Added batch processing to unpixelterm --- unpixelterm.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'unpixelterm.py') diff --git a/unpixelterm.py b/unpixelterm.py index 4091dfb..0969a8f 100755 --- a/unpixelterm.py +++ b/unpixelterm.py @@ -86,13 +86,17 @@ def unpixelterm(text): if __name__ == '__main__': parser = argparse.ArgumentParser(description='Convert images rendered by pixelterm-like utilities back to PNG') - parser.add_argument('input', type=argparse.FileType('r')) - parser.add_argument('output', type=str) + parser.add_argument('input', type=argparse.FileType('r'), nargs='+') + parser.add_argument('-o', '--output', type=str, help='Output file name, defaults to ${input%.pony}.png') + parser.add_argument('-v', '--verbose', action='store_true') args = parser.parse_args() - img, metadata = unpixelterm(args.input.read()) - print('Metadata:') - pnginfo = PngImagePlugin.PngInfo() - for k, v in metadata.items(): - print('{:15}: {}'.format(k, '/'.join(v))) - pnginfo.add_text(k, '/'.join(v)) - img.save(args.output, 'PNG', pnginfo=pnginfo) + for f in args.input: + img, metadata = unpixelterm(f.read()) + if args.verbose: + print('Metadata:') + pnginfo = PngImagePlugin.PngInfo() + for k, v in metadata.items(): + if args.verbose: + print('{:15}: {}'.format(k, '/'.join(v))) + pnginfo.add_text(k, '/'.join(v)) + img.save(args.output or f.name.rstrip('.pony')+'.png', 'PNG', pnginfo=pnginfo) -- cgit