Created
August 5, 2019 19:55
-
-
Save qiuwch/03546d438f92c9d19c50a01016f31b07 to your computer and use it in GitHub Desktop.
Make an html table to preview images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import glob | |
def img_cell(content): | |
return '<td><img src="%s" width="20px"/></td>' % content | |
def make_table(cells, ncol): | |
table = '' | |
for i, cell in enumerate(cells): | |
if i % ncol == 0: | |
table += '<tr>' | |
table += cell | |
if i % ncol == ncol - 1: | |
table += '</tr>' | |
return '<table>%s</table>' % table | |
def main(): | |
imgs = glob.glob('*.png') | |
img_cells = [img_cell(v) for v in imgs] | |
html = make_table(img_cells, 3) | |
with open('index.html', 'w') as f: | |
f.write(html) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment