aboutsummaryrefslogtreecommitdiff
path: root/gifterm.py
diff options
context:
space:
mode:
authorjaseg <s@jaseg.de>2013-05-06 13:59:03 +0200
committerjaseg <s@jaseg.de>2013-05-06 13:59:03 +0200
commit38e5857925092c32647cdf5c19845dbf07eac007 (patch)
tree4a3b85c111c47c2da1af943d4a31fdf6394c4a33 /gifterm.py
parent0c071feaddc6c85606aa77861aa2544d0fe9eaa1 (diff)
downloadpixelterm-38e5857925092c32647cdf5c19845dbf07eac007.tar.gz
pixelterm-38e5857925092c32647cdf5c19845dbf07eac007.tar.bz2
pixelterm-38e5857925092c32647cdf5c19845dbf07eac007.zip
Improve gifterm and pixelterm background handling
Diffstat (limited to 'gifterm.py')
-rwxr-xr-xgifterm.py29
1 files changed, 21 insertions, 8 deletions
diff --git a/gifterm.py b/gifterm.py
index 0fcb6bc..a93e224 100755
--- a/gifterm.py
+++ b/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))