Embed images into Markdown as data URIs
Project description
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

PNG (base64, single line by default):
$ md-img-uri screenshot.png

Enable wrapping at 80 chars:
$ md-img-uri screenshot.png --wrap

Custom wrap width:
$ md-img-uri screenshot.png --wrap 120

Scale image to 400px width:
$ md-img-uri large-photo.jpg --max-width 400

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.

Custom alt text:
$ md-img-uri chart.png --alt "Q4 Revenue Chart"

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
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c3a14db50ae769287fde6335ada408a95fc1f096c7b032324581664f6a96877f
|
|
| MD5 |
c12810fb3217a201b73526fb99e5110a
|
|
| BLAKE2b-256 |
ba41234c88ea87a0bbb20f63f0a8794ae8f48b80e15f77d18b4883ed63341b4c
|
Provenance
The following attestation bundles were made for md_img_uri-0.1.0.tar.gz:
Publisher:
release.yml on rschmied/md-img-uri
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
md_img_uri-0.1.0.tar.gz -
Subject digest:
c3a14db50ae769287fde6335ada408a95fc1f096c7b032324581664f6a96877f - Sigstore transparency entry: 828438935
- Sigstore integration time:
-
Permalink:
rschmied/md-img-uri@18238e27dcd9af55f0d08ca9ddb1a7e9f278c8ef -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/rschmied
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@18238e27dcd9af55f0d08ca9ddb1a7e9f278c8ef -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dfbfd063e688d21bd831e5bb88d6eb06eab2f67afca0db0ecb3998b392f03dd6
|
|
| MD5 |
27419f80ebee31c0c76f7ccbb6839a6a
|
|
| BLAKE2b-256 |
00880a4500d648fff3571c632b5e30cf96ef81740e7b9e96f4089ba9366b12d9
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
md_img_uri-0.1.0-py3-none-any.whl -
Subject digest:
dfbfd063e688d21bd831e5bb88d6eb06eab2f67afca0db0ecb3998b392f03dd6 - Sigstore transparency entry: 828438955
- Sigstore integration time:
-
Permalink:
rschmied/md-img-uri@18238e27dcd9af55f0d08ca9ddb1a7e9f278c8ef -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/rschmied
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@18238e27dcd9af55f0d08ca9ddb1a7e9f278c8ef -
Trigger Event:
push
-
Statement type: