Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- from pathlib import Path
- newlistjpeg = []
- htmlstring2 = ""
- path = input('Enter path of images folder to create html\n')
- parentpath = Path(path).parent
- listjpeg = [os.path.join(path, f) for f in os.listdir(path) if f.lower().endswith(('.jpg', '.jpeg'))]
- htmlstring1 = f'''
- <!DOCTYPE html>
- <html>
- <head>
- <title>My Images</title>
- </head>
- <body>
- <div id="my-images">'''
- for img in listjpeg:
- img = img.replace("\\", "/")
- img = "%20".join(img.split())
- newlistjpeg.append(img)
- listlength = len(newlistjpeg)
- for i in range(0, listlength):
- htmlstring2 += f'''
- <img src="file://{newlistjpeg[i]}" />'''
- htmlstring3 = f'''
- </div>
- </body>
- </html>'''
- fullhtml = htmlstring1 + htmlstring2 + htmlstring3
- with open(os.path.join(parentpath, "index.html"), "w", encoding='utf8') as writefile:
- writefile.write(fullhtml)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement