Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

html_image_embedder-1.0.0.tar.gz (2.3 kB view hashes)

Uploaded Source

Built Distribution

html_image_embedder-1.0.0-py3-none-any.whl (3.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page