Small fix of PNG metadata storage, added metadata support to pixelterm
This commit is contained in:
parent
050fdb036d
commit
1b96018334
2 changed files with 9 additions and 4 deletions
|
|
@ -41,10 +41,10 @@ def termify_pixels(img):
|
||||||
|
|
||||||
def balloon(x,y):
|
def balloon(x,y):
|
||||||
if x+1 == img.size[0] or img.getpixel((x+1, y)) != (0,255,0,127):
|
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):
|
while x-w >= 0 and img.getpixel((x-w, y)) == (0,255,0,127):
|
||||||
w += 1
|
w += 1
|
||||||
return '$balloon{}$'.format(w+1)
|
return '$balloon{}$'.format(w)
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
for y in range(0, sy, 2):
|
for y in range(0, sy, 2):
|
||||||
|
|
@ -87,7 +87,12 @@ if __name__ == '__main__':
|
||||||
print(f)
|
print(f)
|
||||||
foo, _, _ = f.rpartition('.png')
|
foo, _, _ = f.rpartition('.png')
|
||||||
output = os.path.join(args.output_dir, os.path.basename(foo)+'.pony')
|
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:
|
with open(output, 'w') as of:
|
||||||
|
of.write(metadata)
|
||||||
of.write(termify_pixels(img))
|
of.write(termify_pixels(img))
|
||||||
else:
|
else:
|
||||||
print(termify_pixels(img))
|
print(termify_pixels(img))
|
||||||
|
|
|
||||||
|
|
@ -50,10 +50,10 @@ def unpixelterm(text):
|
||||||
k,v = parts
|
k,v = parts
|
||||||
if k not in ['WIDTH', 'HEIGHT']:
|
if k not in ['WIDTH', 'HEIGHT']:
|
||||||
d[k.lower()] = d.get(k.lower(), []) + [v]
|
d[k.lower()] = d.get(k.lower(), []) + [v]
|
||||||
elif l != '':
|
else:
|
||||||
comment.append(l)
|
comment.append(l)
|
||||||
if comment:
|
if comment:
|
||||||
d['comment'] = d.get('comment', []) + comment
|
d['comment'] = d.get('comment', []) + ['\n'.join(comment)]
|
||||||
metadata.update(d)
|
metadata.update(d)
|
||||||
lines[first:] = lines[first+1+second+1:]
|
lines[first:] = lines[first+1+second+1:]
|
||||||
except:
|
except:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue