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

Metadata

Release files for md-img-uri 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for md-img-uri 0.1.0
File Size Uploaded
md_img_uri-0.1.0.tar.gz 5.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for md-img-uri 0.1.0
File Interpreter ABI Platform
md_img_uri-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 11.2 kB

Release files / md_img_uri-0.1.0.tar.gz

Download URL md_img_uri-0.1.0.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
c3a14db50ae769287fde6335ada408a95fc1f096c7b032324581664f6a96877f
BLAKE2b-256 checksum
How to use checksums
ba41234c88ea87a0bbb20f63f0a8794ae8f48b80e15f77d18b4883ed63341b4c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 15, 2026.

Transparency log

Release files / md_img_uri-0.1.0-py3-none-any.whl

Download URL md_img_uri-0.1.0-py3-none-any.whl
Size 6.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dfbfd063e688d21bd831e5bb88d6eb06eab2f67afca0db0ecb3998b392f03dd6
BLAKE2b-256 checksum
How to use checksums
00880a4500d648fff3571c632b5e30cf96ef81740e7b9e96f4089ba9366b12d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 15, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page