Skip to content

Instantly share code, notes, and snippets.

@qiuwch
Created August 5, 2019 19:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qiuwch/03546d438f92c9d19c50a01016f31b07 to your computer and use it in GitHub Desktop.
Save qiuwch/03546d438f92c9d19c50a01016f31b07 to your computer and use it in GitHub Desktop.
Make an html table to preview images
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