root / proj / font / split_font.py @ 186
History | View | Annotate | Download (779 Bytes)
1 | 180 | up20180642 | import os |
---|---|---|---|
2 | import glob |
||
3 | from PIL import Image |
||
4 | |||
5 | im = Image.open("Consolas.png")
|
||
6 | |||
7 | W, H = im.size |
||
8 | |||
9 | Nw = 16
|
||
10 | Nh = 6
|
||
11 | |||
12 | i = 32
|
||
13 | |||
14 | 183 | up20180642 | includes = ""
|
15 | lst = ""
|
||
16 | 180 | up20180642 | |
17 | 183 | up20180642 | for j in range(i): |
18 | if lst != "": lst += "," |
||
19 | lst += "NULL"
|
||
20 | 180 | up20180642 | |
21 | 182 | up20180642 | |
22 | 183 | up20180642 | for h in range(Nh): |
23 | t = int(H/Nh)*h
|
||
24 | b = int(H/Nh)*(h+1) |
||
25 | for w in range(Nw): |
||
26 | #l = int((W*w)/Nw)
|
||
27 | #r = int((W*(w+1))/Nw)
|
||
28 | l = 59*w
|
||
29 | r = 59*(w+1) |
||
30 | im1 = im.crop((l,t,r,b)) |
||
31 | im1.save("png/ascii%03d.png"%i)
|
||
32 | os.system("convert png/ascii%03d.png xpm/ascii%03d.xpm"%(i,i))
|
||
33 | |||
34 | includes += '#include "%03d.xpm"\n'%i
|
||
35 | if lst != "": lst += "," |
||
36 | lst += "%03d_xpm"%i
|
||
37 | 182 | up20180642 | |
38 | 183 | up20180642 | #DEV
|
39 | os.system("rm png/ascii%03d.png"%i)
|
||
40 | 182 | up20180642 | |
41 | 183 | up20180642 | i += 1
|
42 | 182 | up20180642 | |
43 | 183 | up20180642 | os.system('sed -i "s/black/#000000/g" xpm/*.xpm') |