Base64 Images
02 Dec 2023
You can embed an image in the webpage and save a single html file with images included. To do this you need to base64 embed the images.
The pattern for data urls is
data:[<mediatype>][;base64],<data>
The HTML for an image will look like
<img src=“data:image/jpeg;charset=utf-8;base64,<data>”/ >
Python code to generate it will look like
import base64
encoded_image = base64.b64encode(image_binary).encode(‘utf-8’)
- https://docs.python.org/3/library/base64.html
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs
- https://docs.python.org/3/howto/unicode.html