Created
March 5, 2018 06:18
-
-
Save louisswarren/f11c41b586fd3300df972ad60eebe0fd to your computer and use it in GitHub Desktop.
Make a gallery web page of all images in a directory
This file contains hidden or 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 os | |
| import sys | |
| filetypes = ['.gif', '.jpg', '.png'] | |
| fdir = os.path.split(sys.argv[0])[0] | |
| files = os.listdir(fdir) | |
| out = '<!DOCTYPE HTML><html><head><meta charset="utf-8">' | |
| out += """ | |
| <style type="text/css"> | |
| body {width: 100%; align: center} | |
| img { align: center} | |
| </style> | |
| """ | |
| out += '<title>Images in ' + fdir + '</title></head><body>' | |
| for x in files: | |
| if x[-4:].lower() in filetypes: | |
| filtered = x.replace(' ', '%20') | |
| out += '<img src="' + filtered + '" alt="' + filtered + '"><br>' | |
| out += "</body></html>" | |
| f = open('index.html', 'w') | |
| f.write(out) | |
| f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment