Skip to content

Instantly share code, notes, and snippets.

@lubeda
Last active May 5, 2020 21:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lubeda/9994045eecad3ad2a4d92e746a84f4a7 to your computer and use it in GitHub Desktop.
Save lubeda/9994045eecad3ad2a4d92e746a84f4a7 to your computer and use it in GitHub Desktop.
conver 8x8 GIF to Awtrix privatIcons format
#use at your own risk
from PIL import Image,ImageSequence
import sys
def getPixels(filename,text):
img = Image.open(filename, 'r')
w, h = img.size
index = 1
result = ""
for frame in ImageSequence.Iterator(img):
duration = int(frame.info['duration'])
f = frame.convert('RGB')
ret = '['
y = 0
x = 0
for y in range(w):
for x in range(h):
r,g,b = f.getpixel((x,y))
rgb = ((r & 0b11111000) << 8) | ((g & 0b11111100) << 3) | (b >> 3)
ret += str(rgb) + ","
ret = ret[:-1] + ']'
result += ret + ","
result = text+'={"data"\:[' + result[:-1]+'],"tick"\:'+ str(duration) + '}'
print (result)
getPixels(sys.argv[1],sys.argv[2])
"""
Sample:
47={"data"\:[[31,31,0,....8,2016,2016]],"tick"\:100}
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment