Skip to main content

md-img-uri

Embed images into Markdown as data URIs—no external files needed.

Abstract

md-img-uri converts PNG, JPEG, GIF, and SVG images into self-contained Markdown lines using data URIs. Binary formats (PNG/JPEG/GIF) are base64-encoded; SVGs are URL-encoded for smaller output. Useful for portable docs, email-ready Markdown, or single-file distribution.

Features

Encoding:

  • Raster formats (PNG/JPEG/GIF): base64 (~33% size increase)
  • SVG: URL-encoded (compact, no base64 overhead)

Image Scaling:

  • Preserves aspect ratio
  • Pillow-based resizing for raster, SVG attribute injection for vectors
  • Refuses to upscale (warns if --max-width > source width)

Line Wrapping:

  • Default: single-line output (easy piping/parsing)
  • --wrap: multi-line at 80 chars (or custom width)
  • SVGs never wrapped

Limitations

  • Large images → very long lines (base64 inflates ~33%)
  • Some Markdown renderers have size limits
  • Binary files (PNG/JPEG/GIF) become verbose; prefer SVG when possible

Installation

cd md-img-uri
uv sync
.venv/bin/md-img-uri <file>

Or install globally:

uv pip install -e .
md-img-uri <file>

Usage

md-img-uri <file> [OPTIONS]

Arguments:

  • <file>: Image path (.png, .jpg, .jpeg, .gif, .svg)

Options:

  • --alt TEXT: Alt text (defaults to filename stem)
  • --max-width PX: Scale to max width in pixels (no upscaling)
  • --wrap [WIDTH]: Wrap base64 output (default 80 chars, min 40)

Output: Markdown image line with embedded data URI → stdout

Examples

SVG (URL-encoded, single line by default):

$ md-img-uri logo.svg
![logo](data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A//www.w3.org...)

PNG (base64, single line by default):

$ md-img-uri screenshot.png
![screenshot](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...very long single line...)

Enable wrapping at 80 chars:

$ md-img-uri screenshot.png --wrap
![screenshot](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...
...wrapped across multiple lines at 80 chars...)

Custom wrap width:

$ md-img-uri screenshot.png --wrap 120
![screenshot](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...
...wrapped at 120 chars...)

Scale image to 400px width:

$ md-img-uri large-photo.jpg --max-width 400
![large-photo](data:image/jpeg;base64,/9j/4AAQSkZJRgABAQ...)

Upscaling attempt (warns and keeps original):

$ md-img-uri small-icon.png --max-width 500
Warning: Image is 64px wide but --max-width is 500px. Keeping original size to avoid upscaling.
![small-icon](data:image/png;base64,...)

Custom alt text:

$ md-img-uri chart.png --alt "Q4 Revenue Chart"
![Q4 Revenue Chart](data:image/png;base64,iVBORw0KGgo...)

Pipe to file:

$ md-img-uri diagram.svg >> report.md

Supported Formats

Format Encoding MIME Type
PNG base64 image/png
JPEG base64 image/jpeg
GIF base64 image/gif
SVG URL image/svg+xml

Why Data URIs?

  • Portability: Single file, no broken image links
  • Email/Gist: Paste Markdown anywhere without hosting images
  • Archival: Self-contained documentation
  • Offline: Works without network access

License

MIT

Download files

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

Source Distribution

md_img_uri-0.1.0.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

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

md_img_uri-0.1.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file md_img_uri-0.1.0.tar.gz.

File metadata

  • Download URL: md_img_uri-0.1.0.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for md_img_uri-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c3a14db50ae769287fde6335ada408a95fc1f096c7b032324581664f6a96877f
MD5 c12810fb3217a201b73526fb99e5110a
BLAKE2b-256 ba41234c88ea87a0bbb20f63f0a8794ae8f48b80e15f77d18b4883ed63341b4c

See more details on using hashes here.

Provenance

The following attestation bundles were made for md_img_uri-0.1.0.tar.gz:

Publisher: release.yml on rschmied/md-img-uri

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file md_img_uri-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: md_img_uri-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for md_img_uri-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dfbfd063e688d21bd831e5bb88d6eb06eab2f67afca0db0ecb3998b392f03dd6
MD5 27419f80ebee31c0c76f7ccbb6839a6a
BLAKE2b-256 00880a4500d648fff3571c632b5e30cf96ef81740e7b9e96f4089ba9366b12d9

See more details on using hashes here.

Provenance

The following attestation bundles were made for md_img_uri-0.1.0-py3-none-any.whl:

Publisher: release.yml on rschmied/md-img-uri

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Supported by

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