diff options
author | jaseg <s@jaseg.de> | 2013-04-06 17:42:57 +0200 |
---|---|---|
committer | jaseg <s@jaseg.de> | 2013-04-06 17:42:57 +0200 |
commit | 44216123b4b6ead42196339b09441db045547031 (patch) | |
tree | 22e80de4f5fec25431be2b3f02aff6d94a1a02b8 | |
parent | 1bd38f3dac2dad87c0aaed9f303991ebe8b3d7ac (diff) | |
download | pixelterm-44216123b4b6ead42196339b09441db045547031.tar.gz pixelterm-44216123b4b6ead42196339b09441db045547031.tar.bz2 pixelterm-44216123b4b6ead42196339b09441db045547031.zip |
Added batch processing to pixelterm
-rwxr-xr-x | pixelterm.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/pixelterm.py b/pixelterm.py index 4dbcee0..316e674 100755 --- a/pixelterm.py +++ b/pixelterm.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 RGB->X256 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 @@ -80,7 +80,15 @@ def termify_pixels(img): if __name__ == '__main__': parser = argparse.ArgumentParser(description='Render pixel images on 256-color ANSI terminals') - parser.add_argument('image', type=str) + parser.add_argument('image', type=str, nargs='*') + parser.add_argument('-d', '--output-dir', type=str, help='Output directory (if not given, output to stdout)') args = parser.parse_args() - img = Image.open(args.image).convert("RGBA") - print(termify_pixels(img)) + for f in args.image: + img = Image.open(f).convert("RGBA") + if args.output_dir: + foo, _, _ = f.rpartition('.png') + output = os.path.join(args.output_dir, os.path.basename(foo)+'.pony') + with open(output, 'w') as of: + of.write(termify_pixels(img)) + else: + print(termify_pixels(img)) |