forked from mayanklahiri/maxstagram
-
Notifications
You must be signed in to change notification settings - Fork 0
/
html_index_writer.py
74 lines (69 loc) · 1.64 KB
/
html_index_writer.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
71
72
73
74
# Copyright 2013 Mayank Lahiri
# Released under the BSD License
"""Generates a nice HTML preview in the output/ subdirectory."""
import os
output_filename = None
def StartHTML(filename):
'''Writes the header for the HTML preview file.'''
global output_filename
output_filename = filename
fh_html_index = open(output_filename, 'w')
fh_html_index.write('''
<!doctype html>
<html>
<head>
<title>Random Filter Preview</title>
<style type="text/css">
body {
font-family: Verdana, Arial;
}
table {
border: solid 1px black;
font-size: 10px;
}
td {
border: dashed 1px gray;
}
</style>
</head>
<body>
<h1>Filter Preview</h1>
<table>
<tr>
<td>#</td>
<td>Parameters</td>
<td>Images</td>
</tr>
''')
fh_html_index.close()
def WriteHTML(filter_idx, filterop, blendop, outputs, wall_time):
global output_filename
def tdgen(fn): return '<td><img src="' + fn + '"></td>'
outputs = [ os.path.basename(i) for i in outputs ]
table_row = '\n'.join([tdgen(i) for i in outputs ])
fh_html_index = open(output_filename, 'a+')
fh_html_index.write('''
<tr>
<td style="font-size: 24px">{filter_idx}</td>
<td style="width:320px">
<div style="font-weight: bold">Filter:</div>
{filterop}
<div style="font-weight: bold">Blend:</div>
{blendop}
<div style="font-weight: bold">Avg. walltime:</div>
{wall_time} seconds/image
</td>
{table_row}
</tr>
'''.format(**locals()))
fh_html_index.close()
def EndHTML():
global output_filename
fh_html_index = open(output_filename, 'a+')
fh_html_index.write('''
</table>
</body>
</html>
''')
fh_html_index.close()