Converts images to base64 and embeds them in HTML files.
Project description
html_image_embedder
A Python package that embeds images into HTML documents using data URIs.
Installation
You can install html_image_embedder using pip:
pip install html_image_embedder
Usage
To use html_image_embedder, you need to import the embed_images function from the package:
from html_image_embedder import embed_images
The embed_images function takes two arguments: html and images. The html argument is a string containing the HTML code. The images argument is a dictionary mapping image URLs to image bytes. For example, you can use the requests library to get the image bytes from a URL:
import requests
url = "https://example.com/image.png"
response = requests.get(url)
image_bytes = response.content
The embed_images function returns a modified HTML string with the image data embedded in the src attributes of the img tags. For example:
html = "<html><body><img src='https://example.com/image.png'></body></html>"
images = {"https://example.com/image.png": image_bytes}
new_html = embed_images(html, images)
print(new_html)
# <html><body><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."></body></html>
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for html_image_embedder-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | c49e24a4115fd8beb7abfe9e1370f36121e725642bd41bb106fa7803d9002bd1 |
|
MD5 | f35f39ea70e269c5c084f960d0649e32 |
|
BLAKE2b-256 | 0148c22843e9978825fe143d6d0c1751c4f5588115d0ed3f0a818ffb464ee51a |
Hashes for html_image_embedder-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52f2b6d8a7bae551b6d9648b11594a65abe6f7b01422293fb4bbb8dc2d079eed |
|
MD5 | 7b7b8a2a3ed877fdd9eadafb2480796e |
|
BLAKE2b-256 | 34e33d40ea1cbcb5af04debfd366fa260f864122077d4bef3803307379e02c31 |