script reorganization
This commit is contained in:
parent
67a0cf000a
commit
fa2ce0e09d
9 changed files with 209 additions and 233 deletions
197
commands.py
Executable file
197
commands.py
Executable file
|
|
@ -0,0 +1,197 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import os, sys, argparse, os.path, json, time, signal, atexit
|
||||||
|
from collections import defaultdict
|
||||||
|
from pixelterm.pixelterm import termify_pixels, reset_sequence
|
||||||
|
from pixelterm.unpixelterm import unpixelterm
|
||||||
|
from PIL import Image, PngImagePlugin, GifImagePlugin, ImageSequence
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
def pixelterm():
|
||||||
|
import os, sys, argparse, os.path, json
|
||||||
|
from multiprocessing.dummy import Pool
|
||||||
|
from PIL import Image, PngImagePlugin
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
def convert(f):
|
||||||
|
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.get('_comment')
|
||||||
|
if comment is not None:
|
||||||
|
del metadata['_comment']
|
||||||
|
comment = '\n'+comment
|
||||||
|
else:
|
||||||
|
comment = ''
|
||||||
|
metadataarea = '$$$\n' +\
|
||||||
|
'\n'.join([ '\n'.join([ k.upper() + ': ' + v for v in metadata[k] ]) for k in sorted(metadata.keys()) ]) +\
|
||||||
|
comment + '\n$$$\n'
|
||||||
|
with open(output, 'w') as of:
|
||||||
|
of.write(metadataarea)
|
||||||
|
of.write(termify_pixels(img))
|
||||||
|
else:
|
||||||
|
print(termify_pixels(img))
|
||||||
|
|
||||||
|
p = Pool()
|
||||||
|
p.map(convert, args.image)
|
||||||
|
|
||||||
|
|
||||||
|
def unpixelterm():
|
||||||
|
import argparse, json
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description='Convert images rendered by pixelterm-like utilities back to PNG')
|
||||||
|
parser.add_argument('-v', '--verbose', action='store_true')
|
||||||
|
output_group = parser.add_mutually_exclusive_group()
|
||||||
|
output_group.add_argument('-o', '--output', type=str, help='Output file name, defaults to ${input%.pony}.png')
|
||||||
|
output_group.add_argument('-d', '--output-dir', type=str, help='Place output files here')
|
||||||
|
parser.add_argument('input', type=argparse.FileType('r'), nargs='+')
|
||||||
|
args = parser.parse_args()
|
||||||
|
if len(args.input) > 1 and args.output:
|
||||||
|
parser.print_help()
|
||||||
|
print('You probably do not want to overwrite the given output file {} times.'.format(len(args.input)))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
for f in args.input:
|
||||||
|
if len(args.input) > 1:
|
||||||
|
print(f.name)
|
||||||
|
img, metadata = unpixelterm(f.read())
|
||||||
|
pnginfo = PngImagePlugin.PngInfo()
|
||||||
|
pnginfo.add_text('pixelterm-metadata', json.dumps(metadata))
|
||||||
|
foo, _, _ = f.name.rpartition('.pony')
|
||||||
|
output = args.output or foo+'.png'
|
||||||
|
if args.output_dir:
|
||||||
|
output = os.path.join(args.output_dir, os.path.basename(output))
|
||||||
|
img.save(output, 'PNG', pnginfo=pnginfo)
|
||||||
|
|
||||||
|
|
||||||
|
clear_screen = '\033[H\033[2J'
|
||||||
|
home_cursor = '\033[H'
|
||||||
|
cursor_invisible = '\033[?25l'
|
||||||
|
cursor_visible = '\033[?25h'
|
||||||
|
|
||||||
|
def gifterm():
|
||||||
|
parser = argparse.ArgumentParser(description='Render pixel images on 256-color ANSI terminals')
|
||||||
|
parser.add_argument('image', type=str)
|
||||||
|
parser.add_argument('-s', '--size', type=str, help='Terminal size, [W]x[H]')
|
||||||
|
parser.add_argument('--serve', type=int, help='Serve via TCP on given port')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
tw, th = None, None
|
||||||
|
if args.size:
|
||||||
|
tw, th = map(int, args.size.split('x'))
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
tw, th = os.get_terminal_size()
|
||||||
|
except: # If this is not a regular terminal
|
||||||
|
pass
|
||||||
|
th = th*2
|
||||||
|
|
||||||
|
img = Image.open(args.image)
|
||||||
|
palette = img.getpalette()
|
||||||
|
last_frame = Image.new("RGBA", img.size)
|
||||||
|
frames = []
|
||||||
|
|
||||||
|
for frame in ImageSequence.Iterator(img):
|
||||||
|
#This works around a known bug in Pillow
|
||||||
|
#See also: http://stackoverflow.com/questions/4904940/python-converting-gif-frames-to-png
|
||||||
|
frame.putpalette(palette)
|
||||||
|
c = frame.convert("RGBA")
|
||||||
|
|
||||||
|
if img.info['background'] != img.info.get('transparency'):
|
||||||
|
last_frame.paste(c, c)
|
||||||
|
else:
|
||||||
|
last_frame = c
|
||||||
|
|
||||||
|
im = last_frame.copy()
|
||||||
|
if (tw, th) != (None, None):
|
||||||
|
im.thumbnail((tw, th), Image.NEAREST)
|
||||||
|
frames.append(termify_pixels(im, True))
|
||||||
|
|
||||||
|
if args.serve:
|
||||||
|
from socketserver import ThreadingMixIn, TCPServer, BaseRequestHandler
|
||||||
|
|
||||||
|
# Quote-Of-The-Day protocol implementation
|
||||||
|
# See RFC865 ( https://tools.ietf.org/html/rfc865 ) for details.
|
||||||
|
|
||||||
|
class ThreadingTCPServer(ThreadingMixIn, TCPServer): pass
|
||||||
|
|
||||||
|
class QOTDHandler(BaseRequestHandler):
|
||||||
|
def handle(self):
|
||||||
|
try:
|
||||||
|
self.request.sendall(bytes(cursor_invisible, "UTF-8"))
|
||||||
|
while True:
|
||||||
|
for frame in frames:
|
||||||
|
self.request.sendall(bytes(home_cursor + reset_sequence, "UTF-8"))
|
||||||
|
self.request.sendall(bytes(frame, "UTF-8"))
|
||||||
|
time.sleep(min(1/10, img.info['duration']/1000.0))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
server = ThreadingTCPServer(('', args.serve), QOTDHandler)
|
||||||
|
server.serve_forever()
|
||||||
|
else:
|
||||||
|
print(cursor_invisible)
|
||||||
|
atexit.register(lambda:print(cursor_visible))
|
||||||
|
signal.signal(signal.SIGTERM, lambda signum, stack_frame: exit(1))
|
||||||
|
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
for frame in frames:
|
||||||
|
print(home_cursor)
|
||||||
|
print(reset_sequence)
|
||||||
|
print(frame)
|
||||||
|
time.sleep(min(1/10, img.info['duration']/1000.0))
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# Display an xterm-256color color palette on the terminal, including color ids
|
||||||
|
|
||||||
|
reset_sequence = '\033[39;49m'
|
||||||
|
|
||||||
|
def _esc(i):
|
||||||
|
return '\033[48;5;'+str(i)+'m'
|
||||||
|
|
||||||
|
def colorcube():
|
||||||
|
print(''.join([str(i).ljust(4) for i in range(16)]))
|
||||||
|
print(' '.join([_esc(i) for i in range(16)])+' ' + reset_sequence)
|
||||||
|
|
||||||
|
for j in range(6):
|
||||||
|
for k in range(6):
|
||||||
|
c = 16+j*6+k*6*6
|
||||||
|
print(''.join([str(c+i).ljust(4) for i in range(6)]))
|
||||||
|
print(' '.join([_esc(c+i) for i in range(6)])+' ' + reset_sequence)
|
||||||
|
|
||||||
|
print(''.join([str(i).ljust(4) for i in range(16+6*6*6, 16+6*6*6+24)]))
|
||||||
|
print(' '.join([_esc(i) for i in range(16+6*6*6, 16+6*6*6+24)])+' ' + reset_sequence)
|
||||||
|
|
||||||
|
|
||||||
|
def pngmeta():
|
||||||
|
parser = argparse.ArgumentParser(description='Print PNG metadata')
|
||||||
|
parser.add_argument('image', type=str)
|
||||||
|
args = parser.parse_args()
|
||||||
|
img = Image.open(args.image)
|
||||||
|
for k, v in img.info.items():
|
||||||
|
print('{:15}: {}'.format(k, v))
|
||||||
|
|
||||||
|
|
||||||
|
def resolvecolor():
|
||||||
|
import os, sys, argparse, os.path, json, re
|
||||||
|
from pixelterm.xtermcolors import closest_color
|
||||||
|
|
||||||
|
# Resolve HTML-style hex RGB color codes to xterm-256color color numbers
|
||||||
|
|
||||||
|
if len(sys.argv) != 2:
|
||||||
|
print('Usage: resolvecolor.py #RRGGBB')
|
||||||
|
exit()
|
||||||
|
|
||||||
|
print(closest_color(*[int(s, 16) for s in re.match('#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})', sys.argv[1]).groups()]))
|
||||||
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
__all__ = ['xtermcolors', 'pixelterm']
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
# Display an xterm-256color color palette on the terminal, including color ids
|
|
||||||
|
|
||||||
reset_sequence = '\033[39;49m'
|
|
||||||
|
|
||||||
def esc(i):
|
|
||||||
return '\033[48;5;'+str(i)+'m'
|
|
||||||
|
|
||||||
def main():
|
|
||||||
print(''.join([str(i).ljust(4) for i in range(16)]))
|
|
||||||
print(' '.join([esc(i) for i in range(16)])+' ' + reset_sequence)
|
|
||||||
|
|
||||||
for j in range(6):
|
|
||||||
for k in range(6):
|
|
||||||
c = 16+j*6+k*6*6
|
|
||||||
print(''.join([str(c+i).ljust(4) for i in range(6)]))
|
|
||||||
print(' '.join([esc(c+i) for i in range(6)])+' ' + reset_sequence)
|
|
||||||
|
|
||||||
print(''.join([str(i).ljust(4) for i in range(16+6*6*6, 16+6*6*6+24)]))
|
|
||||||
print(' '.join([esc(i) for i in range(16+6*6*6, 16+6*6*6+24)])+' ' + reset_sequence)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
main()
|
|
||||||
|
|
||||||
|
|
@ -1,89 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
import os, sys, argparse, os.path, json, time, signal, atexit
|
|
||||||
import pixelterm
|
|
||||||
from PIL import Image, GifImagePlugin, ImageSequence
|
|
||||||
|
|
||||||
clear_screen = '\033[H\033[2J'
|
|
||||||
home_cursor = '\033[H'
|
|
||||||
cursor_invisible = '\033[?25l'
|
|
||||||
cursor_visible = '\033[?25h'
|
|
||||||
|
|
||||||
def main():
|
|
||||||
parser = argparse.ArgumentParser(description='Render pixel images on 256-color ANSI terminals')
|
|
||||||
parser.add_argument('image', type=str)
|
|
||||||
parser.add_argument('-s', '--size', type=str, help='Terminal size, [W]x[H]')
|
|
||||||
parser.add_argument('--serve', type=int, help='Serve via TCP on given port')
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
tw, th = None, None
|
|
||||||
if args.size:
|
|
||||||
tw, th = map(int, args.size.split('x'))
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
tw, th = os.get_terminal_size()
|
|
||||||
except: # If this is not a regular terminal
|
|
||||||
pass
|
|
||||||
th = th*2
|
|
||||||
|
|
||||||
img = Image.open(args.image)
|
|
||||||
palette = img.getpalette()
|
|
||||||
last_frame = Image.new("RGBA", img.size)
|
|
||||||
frames = []
|
|
||||||
|
|
||||||
for frame in ImageSequence.Iterator(img):
|
|
||||||
#This works around a known bug in Pillow
|
|
||||||
#See also: http://stackoverflow.com/questions/4904940/python-converting-gif-frames-to-png
|
|
||||||
frame.putpalette(palette)
|
|
||||||
c = frame.convert("RGBA")
|
|
||||||
|
|
||||||
if img.info['background'] != img.info.get('transparency'):
|
|
||||||
last_frame.paste(c, c)
|
|
||||||
else:
|
|
||||||
last_frame = c
|
|
||||||
|
|
||||||
im = last_frame.copy()
|
|
||||||
if (tw, th) != (None, None):
|
|
||||||
im.thumbnail((tw, th), Image.NEAREST)
|
|
||||||
frames.append(pixelterm.termify_pixels(im, True))
|
|
||||||
|
|
||||||
if args.serve:
|
|
||||||
from socketserver import ThreadingMixIn, TCPServer, BaseRequestHandler
|
|
||||||
|
|
||||||
# Quote-Of-The-Day protocol implementation
|
|
||||||
# See RFC865 ( https://tools.ietf.org/html/rfc865 ) for details.
|
|
||||||
|
|
||||||
class ThreadingTCPServer(ThreadingMixIn, TCPServer): pass
|
|
||||||
|
|
||||||
class QOTDHandler(BaseRequestHandler):
|
|
||||||
def handle(self):
|
|
||||||
try:
|
|
||||||
self.request.sendall(bytes(cursor_invisible, "UTF-8"))
|
|
||||||
while True:
|
|
||||||
for frame in frames:
|
|
||||||
self.request.sendall(bytes(home_cursor + pixelterm.reset_sequence, "UTF-8"))
|
|
||||||
self.request.sendall(bytes(frame, "UTF-8"))
|
|
||||||
time.sleep(min(1/10, img.info['duration']/1000.0))
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
server = ThreadingTCPServer(('', args.serve), QOTDHandler)
|
|
||||||
server.serve_forever()
|
|
||||||
else:
|
|
||||||
print(cursor_invisible)
|
|
||||||
atexit.register(lambda:print(cursor_visible))
|
|
||||||
signal.signal(signal.SIGTERM, lambda signum, stack_frame: exit(1))
|
|
||||||
|
|
||||||
try:
|
|
||||||
while True:
|
|
||||||
for frame in frames:
|
|
||||||
print(home_cursor)
|
|
||||||
print(pixelterm.reset_sequence)
|
|
||||||
print(frame)
|
|
||||||
time.sleep(min(1/10, img.info['duration']/1000.0))
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
pass
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
main()
|
|
||||||
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import xtermcolors
|
from pixelterm.xtermcolors import closest_color
|
||||||
|
|
||||||
reset_sequence = '\033[39;49m'
|
reset_sequence = '\033[39;49m'
|
||||||
|
|
||||||
|
|
@ -20,7 +20,7 @@ def termify_pixels(img, fill=False):
|
||||||
if color in bgd:
|
if color in bgd:
|
||||||
return bgd[color]
|
return bgd[color]
|
||||||
r,g,b,_ = color
|
r,g,b,_ = color
|
||||||
bgd[color] = '\033[48;5;'+str(xtermcolors.closest_color(r,g,b))+'m'
|
bgd[color] = '\033[48;5;'+str(closest_color(r,g,b))+'m'
|
||||||
return bgd[color]
|
return bgd[color]
|
||||||
|
|
||||||
def fgescape(color):
|
def fgescape(color):
|
||||||
|
|
@ -29,7 +29,7 @@ def termify_pixels(img, fill=False):
|
||||||
return ''
|
return ''
|
||||||
fg=color
|
fg=color
|
||||||
r,g,b,_ = color
|
r,g,b,_ = color
|
||||||
fgd[color] = '\033[38;5;'+str(xtermcolors.closest_color(r,g,b))+'m'
|
fgd[color] = '\033[38;5;'+str(closest_color(r,g,b))+'m'
|
||||||
return fgd[color]
|
return fgd[color]
|
||||||
|
|
||||||
def balloon(x,y):
|
def balloon(x,y):
|
||||||
|
|
@ -69,41 +69,3 @@ def termify_pixels(img, fill=False):
|
||||||
out = (out.rstrip() if bg == (0,0,0,0) and not fill else out) + '\n'
|
out = (out.rstrip() if bg == (0,0,0,0) and not fill else out) + '\n'
|
||||||
return out[:-1] + reset_sequence + '\n'
|
return out[:-1] + reset_sequence + '\n'
|
||||||
|
|
||||||
def main():
|
|
||||||
import os, sys, argparse, os.path, json
|
|
||||||
from multiprocessing.dummy import Pool
|
|
||||||
from PIL import Image, PngImagePlugin
|
|
||||||
|
|
||||||
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()
|
|
||||||
|
|
||||||
def convert(f):
|
|
||||||
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.get('_comment')
|
|
||||||
if comment is not None:
|
|
||||||
del metadata['_comment']
|
|
||||||
comment = '\n'+comment
|
|
||||||
else:
|
|
||||||
comment = ''
|
|
||||||
metadataarea = '$$$\n' +\
|
|
||||||
'\n'.join([ '\n'.join([ k.upper() + ': ' + v for v in metadata[k] ]) for k in sorted(metadata.keys()) ]) +\
|
|
||||||
comment + '\n$$$\n'
|
|
||||||
with open(output, 'w') as of:
|
|
||||||
of.write(metadataarea)
|
|
||||||
of.write(termify_pixels(img))
|
|
||||||
else:
|
|
||||||
print(termify_pixels(img))
|
|
||||||
|
|
||||||
p = Pool()
|
|
||||||
p.map(convert, args.image)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
main()
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
import os, sys, argparse
|
|
||||||
from PIL import Image, PngImagePlugin
|
|
||||||
|
|
||||||
def main():
|
|
||||||
parser = argparse.ArgumentParser(description='Print PNG metadata')
|
|
||||||
parser.add_argument('image', type=str)
|
|
||||||
args = parser.parse_args()
|
|
||||||
img = Image.open(args.image)
|
|
||||||
for k, v in img.info.items():
|
|
||||||
print('{:15}: {}'.format(k, v))
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
main()
|
|
||||||
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
def main():
|
|
||||||
import os, sys, argparse, os.path, json, re
|
|
||||||
from pixelterm import xtermcolors
|
|
||||||
|
|
||||||
# Resolve HTML-style hex RGB color codes to xterm-256color color numbers
|
|
||||||
|
|
||||||
if len(sys.argv) != 2:
|
|
||||||
print('Usage: resolvecolor.py #RRGGBB')
|
|
||||||
exit()
|
|
||||||
|
|
||||||
print(xtermcolors.closest_color(*[int(s, 16) for s in re.match('#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})', sys.argv[1]).groups()]))
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
main()
|
|
||||||
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
import os, sys, os.path
|
import os, sys, os.path
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from pixelterm import xtermcolors
|
from pixelterm.xtermcolors import xterm_colors
|
||||||
from PIL import Image, PngImagePlugin
|
from PIL import Image, PngImagePlugin
|
||||||
try:
|
try:
|
||||||
import re2 as re
|
import re2 as re
|
||||||
|
|
@ -16,7 +16,7 @@ def parse_escape_sequence(seq):
|
||||||
while i<len(codes):
|
while i<len(codes):
|
||||||
if codes[i] in [38, 48]:
|
if codes[i] in [38, 48]:
|
||||||
if codes[i+1] == 5:
|
if codes[i+1] == 5:
|
||||||
c = xtermcolors.xterm_colors[codes[i+2]]
|
c = xterm_colors[codes[i+2]]
|
||||||
fg, bg = (c, bg) if codes[i] == 38 else (fg, c)
|
fg, bg = (c, bg) if codes[i] == 38 else (fg, c)
|
||||||
i += 2
|
i += 2
|
||||||
elif codes[i] == 39:
|
elif codes[i] == 39:
|
||||||
|
|
@ -90,33 +90,3 @@ def unpixelterm(text):
|
||||||
x, y = 0, y+2
|
x, y = 0, y+2
|
||||||
return img, metadata
|
return img, metadata
|
||||||
|
|
||||||
def main():
|
|
||||||
import argparse, json
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='Convert images rendered by pixelterm-like utilities back to PNG')
|
|
||||||
parser.add_argument('-v', '--verbose', action='store_true')
|
|
||||||
output_group = parser.add_mutually_exclusive_group()
|
|
||||||
output_group.add_argument('-o', '--output', type=str, help='Output file name, defaults to ${input%.pony}.png')
|
|
||||||
output_group.add_argument('-d', '--output-dir', type=str, help='Place output files here')
|
|
||||||
parser.add_argument('input', type=argparse.FileType('r'), nargs='+')
|
|
||||||
args = parser.parse_args()
|
|
||||||
if len(args.input) > 1 and args.output:
|
|
||||||
parser.print_help()
|
|
||||||
print('You probably do not want to overwrite the given output file {} times.'.format(len(args.input)))
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
for f in args.input:
|
|
||||||
if len(args.input) > 1:
|
|
||||||
print(f.name)
|
|
||||||
img, metadata = unpixelterm(f.read())
|
|
||||||
pnginfo = PngImagePlugin.PngInfo()
|
|
||||||
pnginfo.add_text('pixelterm-metadata', json.dumps(metadata))
|
|
||||||
foo, _, _ = f.name.rpartition('.pony')
|
|
||||||
output = args.output or foo+'.png'
|
|
||||||
if args.output_dir:
|
|
||||||
output = os.path.join(args.output_dir, os.path.basename(output))
|
|
||||||
img.save(output, 'PNG', pnginfo=pnginfo)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
main()
|
|
||||||
|
|
||||||
|
|
|
||||||
19
setup.py
19
setup.py
|
|
@ -24,19 +24,14 @@ setup(name = 'pixelterm',
|
||||||
url = 'https://github.com/jaseg/pixelterm',
|
url = 'https://github.com/jaseg/pixelterm',
|
||||||
packages = ['pixelterm'],
|
packages = ['pixelterm'],
|
||||||
install_requires=['pillow'],
|
install_requires=['pillow'],
|
||||||
scripts = [ 'pixelterm/pixelterm.py',
|
py_modules = [ 'commands' ],
|
||||||
'pixelterm/unpixelterm.py',
|
|
||||||
'pixelterm/gifterm.py',
|
|
||||||
'pixelterm/colorcube.py',
|
|
||||||
'pixelterm/resolvecolor.py'],
|
|
||||||
entry_points = {'console_scripts': [
|
entry_points = {'console_scripts': [
|
||||||
'pixelterm=pixelterm.pixelterm:main',
|
'pixelterm=commands:pixelterm',
|
||||||
'unpixelterm=pixelterm.unpixelterm:main',
|
'unpixelterm=commands:unpixelterm',
|
||||||
'gifterm=pixelterm.gifterm:main',
|
'gifterm=commands:gifterm',
|
||||||
'colorcube=pixelterm.colorcube:main',
|
'colorcube=commands:colorcube',
|
||||||
'resolvecolor=pixelterm.resolvecolor:main',
|
'resolvecolor=commands:resolvecolor',
|
||||||
'pngmeta=pixelterm.pngmeta:main']},
|
'pngmeta=commands:pngmeta']},
|
||||||
zip_safe = True,
|
|
||||||
classifiers = [
|
classifiers = [
|
||||||
'Development Status :: 5 - Production/Stable',
|
'Development Status :: 5 - Production/Stable',
|
||||||
'Environment :: Console',
|
'Environment :: Console',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue