diff options
author | jaseg <s@jaseg.de> | 2013-04-06 18:15:00 +0200 |
---|---|---|
committer | jaseg <s@jaseg.de> | 2013-04-06 18:31:43 +0200 |
commit | 1b9601833475bf6f4dbee024d90c76bce0d25342 (patch) | |
tree | 8ac4c9e3335ae21916078719555117785dfe62a2 | |
parent | 050fdb036d3a0434b5d2cb623c8874d56a9ecebb (diff) | |
download | pixelterm-1b9601833475bf6f4dbee024d90c76bce0d25342.tar.gz pixelterm-1b9601833475bf6f4dbee024d90c76bce0d25342.tar.bz2 pixelterm-1b9601833475bf6f4dbee024d90c76bce0d25342.zip |
Small fix of PNG metadata storage, added metadata support to pixelterm
-rwxr-xr-x | pixelterm.py | 9 | ||||
-rwxr-xr-x | unpixelterm.py | 4 |
2 files changed, 9 insertions, 4 deletions
diff --git a/pixelterm.py b/pixelterm.py index fbaea9a..a0569de 100755 --- a/pixelterm.py +++ b/pixelterm.py @@ -41,10 +41,10 @@ def termify_pixels(img): def balloon(x,y): if x+1 == img.size[0] or img.getpixel((x+1, y)) != (0,255,0,127): - w = 0 + w = 1 while x-w >= 0 and img.getpixel((x-w, y)) == (0,255,0,127): w += 1 - return '$balloon{}$'.format(w+1) + return '$balloon{}$'.format(w) return '' for y in range(0, sy, 2): @@ -87,7 +87,12 @@ 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', '') +\ + '\n$$$\n' with open(output, 'w') as of: + of.write(metadata) of.write(termify_pixels(img)) else: print(termify_pixels(img)) diff --git a/unpixelterm.py b/unpixelterm.py index e1af6d1..47d05cb 100755 --- a/unpixelterm.py +++ b/unpixelterm.py @@ -50,10 +50,10 @@ def unpixelterm(text): k,v = parts if k not in ['WIDTH', 'HEIGHT']: d[k.lower()] = d.get(k.lower(), []) + [v] - elif l != '': + else: comment.append(l) if comment: - d['comment'] = d.get('comment', []) + comment + d['comment'] = d.get('comment', []) + ['\n'.join(comment)] metadata.update(d) lines[first:] = lines[first+1+second+1:] except: |