-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconverter_simple.py
executable file
·71 lines (53 loc) · 1.11 KB
/
converter_simple.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python3
import numpy as np
from PIL import Image
from sys import argv
from tqdm import tqdm
class converter:
_data="""\
<html>
<body>
<style>
body {
display: block;
}
table {
margin: 0px;
padding: 0px;
border-spacing: 0px;
}
tr {
margin: 0px;
padding: 0px;
}
td {
width: 1px;
height: 1px;
margin: 0px;
padding: 0px;
}
</style>
<table style="border-spacing: 0px;">"""
def __init__(self):
self._img=Image.open(argv[1])
self._bitmap=np.array(self._img)
self._output_file='data.html'
self._convert()
self._save()
def cod(self,col):
return f"""<td style="background-color: {col}"></td>"""
def col(self,r,g,b):
return '#%02x%02x%02x' % (r, g, b)
def _convert(self):
for x in tqdm(range(0,self._img.size[1], 1)):
self._data+="<tr>"
for y in range(0,self._img.size[0], 1):
self._data+=self.cod(self.col(self._bitmap[x][y][0],self._bitmap[x][y][1],self._bitmap[x][y][2]))
self._data+="</tr>"
self._data+="</table></body></html> "
def _save(self):
with open(self._output_file,'w') as f:
f.write(self._data)
f.close()
if __name__=="__main__":
c=converter()