diff options
author | jaseg <s@jaseg.de> | 2013-04-06 16:38:22 +0200 |
---|---|---|
committer | jaseg <s@jaseg.de> | 2013-04-06 16:38:22 +0200 |
commit | 658c18576084b7cb35724291f9b531046ff57603 (patch) | |
tree | 0ff4fe3eaf7727e66d3f546e0758a3305f493f9e | |
parent | d09a64ce01b37fa67c905df1a28f81f91d59e065 (diff) | |
download | pixelterm-658c18576084b7cb35724291f9b531046ff57603.tar.gz pixelterm-658c18576084b7cb35724291f9b531046ff57603.tar.bz2 pixelterm-658c18576084b7cb35724291f9b531046ff57603.zip |
Added -d to unpixelterm to place files in another folder)
-rwxr-xr-x | unpixelterm.py | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/unpixelterm.py b/unpixelterm.py index 0969a8f..d08e824 100755 --- a/unpixelterm.py +++ b/unpixelterm.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -import os, sys, argparse +import os, sys, argparse, os.path #NOTE: This script uses pygments for X256->RGB conversion since pygments is #readily available. If you do not like pygments (e.g. because it is large), #you could patch in something like https://github.com/magarcia/python-x256 @@ -86,10 +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'), 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') + output_group = parser.add_mutually_exclusive_group() + output_group.add_argument('-o', '--output', type=str, help='Output file name, defaults to ${input%.pony}.png') + output_group.add_argument('-d', '--output-dir', type=str, help='Place output files here') + parser.add_argument('input', type=argparse.FileType('r'), nargs='+') args = parser.parse_args() + if len(args.input) > 1 and args.output: + parser.print_help() + print('You probably do not want to overwrite the given output file {} times.'.format(len(args.input))) + sys.exit(1) + for f in args.input: img, metadata = unpixelterm(f.read()) if args.verbose: @@ -99,4 +106,7 @@ if __name__ == '__main__': 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) + output = args.output or f.name.rstrip('.pony')+'.png' + if args.output_dir: + output = os.path.join(args.output_dir, os.path.basename(output)) + img.save(output, 'PNG', pnginfo=pnginfo) |