-
Notifications
You must be signed in to change notification settings - Fork 0
/
txt_to_pic.py
37 lines (31 loc) · 832 Bytes
/
txt_to_pic.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from PIL import Image, ImageOps, ImageDraw, ImageFont
from os.path import isfile
ub_m = ImageFont.truetype("./fonts/Ubuntu-M.ttf", 12, encoding = 'unic')
FOREGROUND = (255,255,255)
def imagify(filename):
f = open(filename)
img = Image.new("L", (107 * 9, 40 * 18), "black")
draw = ImageDraw.Draw(img)
y = 1
for line in f.readlines():
line = line[0:-1]
x = 1
for char in line:
draw.text((x, y * 18), char, font = ub_m, fill = 255)
x = x + 9
y = y + 1
img.show()
save = "." + filename.split('.')[1] + ".jpg"
print save
img.save(save)
def imagify_all():
for i in range(1,6573):
num = str(i)
zeros = (8 - len(num)) * "0"
name = "./out/" + zeros + num + ".txt"
if(isfile(name[0:17] + ".jpg")):
continue
imagify(name)
if(__name__ == "__main__"):
imagify_all()
# imagify("./result/00000100.txt")