aboutsummaryrefslogtreecommitdiff
path: root/pixelterm.py
diff options
context:
space:
mode:
authorjaseg <s@jaseg.de>2013-04-07 13:15:09 +0200
committerjaseg <s@jaseg.de>2013-04-07 13:15:09 +0200
commit97228be04424648c368ce71ab13bcf9581935ea4 (patch)
tree5ab060a7d725f64110fb56a72d20cd0fecc65be5 /pixelterm.py
parentefbf9145c32c60021f8224b5644727bbe3505767 (diff)
downloadpixelterm-97228be04424648c368ce71ab13bcf9581935ea4.tar.gz
pixelterm-97228be04424648c368ce71ab13bcf9581935ea4.tar.bz2
pixelterm-97228be04424648c368ce71ab13bcf9581935ea4.zip
Made a more sane png-metadata format
Diffstat (limited to 'pixelterm.py')
-rwxr-xr-xpixelterm.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/pixelterm.py b/pixelterm.py
index 5db15a1..d47d1a8 100755
--- a/pixelterm.py
+++ b/pixelterm.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
-import os, sys, argparse, os.path
+import os, sys, argparse, os.path, json
#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
@@ -87,12 +87,15 @@ if __name__ == '__main__':
print(f)
foo, _, _ = f.rpartition('.png')
output = os.path.join(args.output_dir, os.path.basename(foo)+'.pony')
- metadata = '$$$\n' +\
- '\n'.join([ k.upper()+': '+img.info[k] for k in sorted(img.info.keys()) if k != 'comment' ]) +\
- '\n' + img.info.get('comment', '') +\
+ 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(metadata)
+ of.write(metadataarea)
of.write(termify_pixels(img))
else:
print(termify_pixels(img))