aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjaseg <s@jaseg.de>2013-04-06 16:26:13 +0200
committerjaseg <s@jaseg.de>2013-04-06 16:26:28 +0200
commitd09a64ce01b37fa67c905df1a28f81f91d59e065 (patch)
tree8c4c7c7b8bdb0c7aedf9c26c590eec17c5d5828e
parent8b20e1d4336f5ba5bb28ef2176abacfe832968b2 (diff)
downloadpixelterm-d09a64ce01b37fa67c905df1a28f81f91d59e065.tar.gz
pixelterm-d09a64ce01b37fa67c905df1a28f81f91d59e065.tar.bz2
pixelterm-d09a64ce01b37fa67c905df1a28f81f91d59e065.zip
Added batch processing to unpixelterm
-rwxr-xr-xunpixelterm.py22
1 files changed, 13 insertions, 9 deletions
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)