How to: Presentations with svg in the browser (html + Python)

I will use Python to make a script that creates an html file that loads all the images in svg format that are present in a folder (where the python script is) so that it will show all the images in the browser, one after another like in a presentation (all together in vertical allignment). It could be useful to make presentations without the need of having any program to use to show them but any browser. You could also not carry your images around, but just the html file, storing the images in a repository, giving the link of the images into the code. A simple trick to do it automatically, is to have the same images in the local folder and then add to each file name (grabbed with the glob function) the initial address of the repository. Another simple thing to do is to bring the folder with files and the “loader.html” file into a repository, so that you do not have to carry anything to show the presentation. You just need to launch the loader.html fron the link. See ya.

import os
from glob import glob


def load(fill=0):
    template = ""
    img = [i for i in glob("*.svg")]
    for i in img:
        if fill:
            template += f"<img src='{i}' style='width:100%; height:100%'>"
        else:
            template += f"<img src='{i}'>"

    return template


html = """<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf-8">
<style>
</style>
    <title></title>
</head>
<body>
<<template>>
</body>
</html>"""

html = html.replace("<<template>>", load(fill=0))

with open("loader.html", "w") as file:
    file.write(html)
os.startfile("loader.html")

Video coding live


Subscribe to the newsletter for updates
Tkinter templates
Avatar My youtube channel

Twitter: @pythonprogrammi - python_pygame

Videos

Speech recognition game

Pygame's Platform Game

Other Pygame's posts

Published by pythonprogramming

Started with basic on the spectrum, loved javascript in the 90ies and python in the 2000, now I am back with python, still making some javascript stuff when needed.