Improve gifterm and pixelterm background handling
This commit is contained in:
parent
0c071feadd
commit
38e5857925
4 changed files with 23 additions and 10 deletions
|
|
@ -28,5 +28,5 @@ are only parsed for the upper of the two rows. An example image is included.
|
|||
|
||||
Credits
|
||||
-------
|
||||
That awesome Rainbow Dash is by [starsteppony on deviantart](http://starsteppony.deviantart.com/art/Rainbow-Dash-Salute-263753912)
|
||||
That awesome Rainbow Dash is by [starsteppony on deviantart](http://starsteppony.deviantart.com/art/Rainbow-Dash-Salute-263753912). Credit for pop tart cat/nyan cat goes to [prguitarman from tumblr](http://prguitarman.tumblr.com/post/4281177195/pop-tart-cat-icon-can-be-found-here).
|
||||
|
||||
|
|
|
|||
29
gifterm.py
29
gifterm.py
|
|
@ -16,20 +16,33 @@ cursor_visible = '\033[?25h'
|
|||
if __name__ == '__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]')
|
||||
args = parser.parse_args()
|
||||
img = Image.open(args.image)
|
||||
frames = []
|
||||
palette = img.getpalette()
|
||||
|
||||
tw, th = os.get_terminal_size()
|
||||
th = th*2
|
||||
if args.size:
|
||||
tw, th = map(int, args.size.split('x'))
|
||||
|
||||
img = Image.open(args.image)
|
||||
palette = img.getpalette()
|
||||
last_frame = Image.new("RGBA", img.size)
|
||||
frames = []
|
||||
|
||||
for frame in ImageSequence.Iterator(img):
|
||||
f = frame.copy()
|
||||
#This works around a known bug in Pillow
|
||||
#See also: http://stackoverflow.com/questions/4904940/python-converting-gif-frames-to-png
|
||||
f.putpalette(palette)
|
||||
f = f.convert("RGBA")
|
||||
f.thumbnail((tw, th), Image.ANTIALIAS)
|
||||
frames.append(pixelterm.termify_pixels(f))
|
||||
frame.putpalette(palette)
|
||||
c = frame.convert("RGBA")
|
||||
|
||||
if img.info['background'] != img.info['transparency']:
|
||||
last_frame.paste(c, c)
|
||||
else:
|
||||
last_frame = c
|
||||
|
||||
im = last_frame.copy()
|
||||
im.thumbnail((tw, th), Image.NEAREST)
|
||||
frames.append(pixelterm.termify_pixels(im))
|
||||
|
||||
print(cursor_invisible)
|
||||
atexit.register(lambda:print(cursor_visible))
|
||||
|
|
|
|||
BIN
nyancat.gif
Normal file
BIN
nyancat.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 30 KiB |
|
|
@ -73,7 +73,7 @@ def termify_pixels(img):
|
|||
if colbot == coltop:
|
||||
c,te,be = cf,te,te
|
||||
out += te(coltop) + be(colbot) + c
|
||||
out = out.rstrip() + '\n'
|
||||
out = (out.rstrip() if bg == (0,0,0,0) else out) + '\n'
|
||||
return out[:-1] + reset_sequence + '\n'
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue