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 details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

Details for the file html_image_embedder-1.0.0.tar.gz.

File metadata

  • Download URL: html_image_embedder-1.0.0.tar.gz
  • Upload date:
  • Size: 2.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for html_image_embedder-1.0.0.tar.gz
Algorithm Hash digest
SHA256 23f6a88960c8a0cca294f4aa5c95848cd75c3bd11f629681a39f4c945e70defb
MD5 6c310286a3cfbfd9bf07a4498f15a34b
BLAKE2b-256 cd4285fb4c94a12f054e30600cece4ef9aca75974a4bcf5fb0def9dd48f41d11

See more details on using hashes here.

File details

Details for the file html_image_embedder-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for html_image_embedder-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3ca90dff065c84e0cb2302360448b0d053cff3be2800afffcb90e8eb1750b6f9
MD5 ce2b7928d79e7c95141e09e91d6e7232
BLAKE2b-256 a2db4eea0a6cbb833f24def7a8896de56c850b46430133c92f0b92b6c8035a60

See more details on using hashes here.

Supported by

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