mirror of
git://projects.qi-hardware.com/iris.git
synced 2024-11-17 14:30:36 +02:00
31 lines
999 B
Python
Executable File
31 lines
999 B
Python
Executable File
#!/usr/bin/env python
|
|
import sys
|
|
import os
|
|
from PIL import Image
|
|
|
|
def mknum (num):
|
|
return ''.join ([chr ((num >> (8 * i)) & 0xff) for i in range (4)])
|
|
|
|
im = Image.open (sys.argv[1])
|
|
height = im.size[1]
|
|
width, baseline, skip = [int (x) for x in os.path.splitext (sys.argv[1])[0].split ('-')[-1].split ('+')]
|
|
num_glyphs = im.size[0] / width
|
|
sys.stdout.write (mknum (skip + num_glyphs))
|
|
size1 = (3 + width * height) * 4
|
|
base = (num_glyphs + skip) * 4
|
|
for i in range (skip):
|
|
sys.stdout.write (mknum (base + (num_glyphs - 1) * size1))
|
|
for i in range (skip, skip + num_glyphs):
|
|
sys.stdout.write (mknum (base + (i - skip) * size1))
|
|
|
|
im = im.convert ('RGBA')
|
|
pix = im.load ()
|
|
#sys.stderr.write ('%d\n' % len (pix[0,0]))
|
|
for g in range (skip, skip + num_glyphs):
|
|
sys.stdout.write (mknum (width))
|
|
sys.stdout.write (mknum (height))
|
|
sys.stdout.write (mknum (baseline))
|
|
for y in range (height):
|
|
for x in range (width):
|
|
sys.stdout.write (''.join ([chr (x) for x in (pix[x + (g - skip) * width, y])]))
|