aboutsummaryrefslogtreecommitdiff
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
parent0c071feaddc6c85606aa77861aa2544d0fe9eaa1 (diff)
downloadpixelterm-38e5857925092c32647cdf5c19845dbf07eac007.tar.gz
pixelterm-38e5857925092c32647cdf5c19845dbf07eac007.tar.bz2
pixelterm-38e5857925092c32647cdf5c19845dbf07eac007.zip
Improve gifterm and pixelterm background handling
-rw-r--r--README.md2
-rwxr-xr-xgifterm.py29
-rw-r--r--nyancat.gifbin0 -> 30244 bytes
-rwxr-xr-xpixelterm.py2
4 files changed, 23 insertions, 10 deletions
diff --git a/README.md b/README.md
index b591fcf..cdc8854 100644
--- a/README.md
+++ b/README.md
@@ -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).
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))
diff --git a/nyancat.gif b/nyancat.gif
new file mode 100644
index 0000000..9c2ad57
--- /dev/null
+++ b/nyancat.gif
Binary files differ
diff --git a/pixelterm.py b/pixelterm.py
index d47d1a8..ab4409c 100755
--- a/pixelterm.py
+++ b/pixelterm.py
@@ -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__':