Skip to content

Instantly share code, notes, and snippets.

@hsgw
Created October 7, 2016 19:07
Show Gist options
  • Save hsgw/7ec95b8f569e6746b79e12441f66dc24 to your computer and use it in GitHub Desktop.
Save hsgw/7ec95b8f569e6746b79e12441f66dc24 to your computer and use it in GitHub Desktop.
GIFアニメ再生するやつ
# -*- coding utf-8 -*-
import sys,time
import numpy
from PIL import Image, ImageSequence
def clearDisplay():
print("\033[2J",end='')
def printPixel(color):
colorIn256 = 16 + round(color[0]/255*5) * 36 + round(color[1]/255*5) * 6 + round(color[2]/255*5)
print("\033[48;5;{0:d}m \033[49m".format(int(colorIn256)) , end='')
def calcPixel(color):
colorIn256 = 16 + round(color[0]/255*5) * 36 + round(color[1]/255*5) * 6 + round(color[2]/255*5)
return ("\033[48;5;{0:d}m \033[49m".format(int(colorIn256)))
def printFrame(frame):
output = ""
pixels = numpy.asarray(frame.convert('RGB'))
for row in pixels:
for pixel in row:
#printPixel(pixel)
output += calcPixel(pixel)
output += "\n"
print(output, end="")
try:
print("open file")
gif = Image.open("1.gif")
except IOError:
print("can't open file")
sys.exit()
while True:
for frame in ImageSequence.Iterator(gif):
clearDisplay()
printFrame(frame)
time.sleep(frame.info['duration']/1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment