A utility that embeds external images in Markdown files as base64-encoded data URLs, creating completely self-contained documents.
- Converts both local and remote images in Markdown to base64-encoded data URLs
- Automatically compresses images to reduce file size
- Intelligent quality adjustment based on image size
- Supports both standard Markdown image syntax and Obsidian-style![[image.jpg]]
- Makes remote images clickable, linking to their original URLs
- Configurable compression quality
- Supports various image formats (JPG, PNG, GIF, etc.)
- Preserves image dimensions when specified
- Skips already embedded images and video files
- Python 3.6+
- Required Python packages:
- Pillow (PIL)
- requests
 
# Clone the repository
git clone https://github.com/yourusername/markdown-image-embedder.git
cd markdown-image-embedder
# Install dependencies
pip install pillow requests# Process a Markdown file
python markdown_image_embedder.py -i input.md -o output.md
# Pipe content through stdin/stdout
cat input.md | python markdown_image_embedder.py > output.mdEmbed images with default settings:
python markdown_image_embedder.py -i notes.md -o notes_embedded.mdSpecify a base path for relative image links:
python markdown_image_embedder.py -i notes.md -o notes_embedded.md -p /path/to/imagesSet higher image quality (lower value = higher quality):
python markdown_image_embedder.py -i notes.md -o notes_embedded.md -q 2Enable Obsidian/Yarle compatibility mode:
python markdown_image_embedder.py -i notes.md -o notes_embedded.md -y| Option | Short | Default | Description | 
|---|---|---|---|
| --input-file | -i | stdin | Input Markdown file path | 
| --output-file | -o | stdout | Output Markdown file path | 
| --quality | -q | 5 | Quality scale (1-9, lower = higher quality) | 
| --yarle | -y | False | Enable Yarle compatibility mode | 
| --max-size | -m | 10 | Maximum file size to embed in MB | 
| --path | -p | "" | Base path for resolving relative file paths | 
| --debug | -d | False | Enable debug logging level | 
| --verbose | -v | False | Enable verbose logging level | 
- Create self-contained documents that don't rely on external resources
- Prevent broken image links when sharing Markdown files
- Simplify document sharing without separate image folders
- Optimize file size with automatic compression
- Preserve offline access to all content