-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimg2ascii.py
34 lines (31 loc) · 1.06 KB
/
img2ascii.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
from ascii_magic import AsciiArt
from os import listdir
from random import shuffle
# turn images to ascii
html_fnames = []
for f in listdir("img/cats"):
print(f'Generating {f}')
my_art = AsciiArt.from_image(f'img/cats/{f}')
my_art.to_html_file(f'img/ascii/{f}.html', monochrome=False, columns=200, additional_styles='font-weight: 900;')
html_fnames.append(f'img/ascii/{f}.html')
# concatenate resulting ascii
shuffle(html_fnames)
newdoc = """<!DOCTYPE html>
<head>
<title>eepy cats</title>
</head>
<body style="background-color:#000000;">"""
for fname in html_fnames:
print(f'Concatenating {f}')
openfile = open(fname)
content = openfile.readlines()[6]
newdoc += f'<div style="text-align: center; align: center;">\n{content}</div>\n'
newdoc += """
<div style="text-align: center; align: center;">
<a style="color: white;">submit cat pics / enviar fotos de gats: eepycats at fbcf · xyz</a>
</div>
</body>"""
# write out
print('Writing out')
with open("publish/index.html", "w") as text_file:
text_file.write(newdoc)