diff options
author | jaseg <s@jaseg.de> | 2013-07-29 18:51:18 +0200 |
---|---|---|
committer | jaseg <s@jaseg.de> | 2013-07-29 18:51:18 +0200 |
commit | a79ab969533320582482856758394e74739b152e (patch) | |
tree | 59e320c15a282cb57318683815c8e3d529e2f087 /pixelterm | |
parent | 62e62f1eace5899d0176ef0dd1b66c6ef72f7ab0 (diff) | |
download | pixelterm-a79ab969533320582482856758394e74739b152e.tar.gz pixelterm-a79ab969533320582482856758394e74739b152e.tar.bz2 pixelterm-a79ab969533320582482856758394e74739b152e.zip |
Made a proper python package out of this.
Diffstat (limited to 'pixelterm')
-rwxr-xr-x | pixelterm | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/pixelterm b/pixelterm new file mode 100755 index 0000000..f893875 --- /dev/null +++ b/pixelterm @@ -0,0 +1,28 @@ +#!/usr/bin/env python + +import os, sys, argparse, os.path, json, pixelterm +from PIL import Image, PngImagePlugin + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='Render pixel images on 256-color ANSI terminals') + 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() + for f in args.image: + img = Image.open(f).convert("RGBA") + if args.output_dir: + print(f) + foo, _, _ = f.rpartition('.png') + output = os.path.join(args.output_dir, os.path.basename(foo)+'.pony') + metadata = json.loads(img.info.get('pixelterm-metadata')) + comment = metadata['_comment'] + del metadata['_comment'] + metadataarea = '$$$\n' +\ + '\n'.join([ '\n'.join([ k.upper() + ': ' + v for v in metadata[k] ]) for k in sorted(metadata.keys()) ]) +\ + '\n' + comment +\ + '\n$$$\n' + with open(output, 'w') as of: + of.write(metadataarea) + of.write(pixelterm.termify_pixels(img)) + else: + print(pixelterm.termify_pixels(img)) |