diff options
-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: |