AgentSkillsCN

convert-external-images

将外部图像文件(如Obsidian风格的![[image.png]]或标准的![](image.png))转换为嵌入式Base64数据URL,以Markdown格式呈现。采用引用式语法,在正文末尾附上Base64编码的数据,使主文本更加简洁。支持PNG、JPG、JPEG、GIF、WEBP等多种格式。同时具备备份、校验功能,并可选择性地清理原始文件。

SKILL.md
--- frontmatter
name: convert-external-images
description: Convert external image files (Obsidian-style ![[image.png]] or standard ![](image.png)) to embedded base64 data URLs in markdown. Uses reference-style syntax for clean main text with base64 data at file end. Supports PNG, JPG, JPEG, GIF, WEBP. Includes backup, verification, and optional cleanup of original files.

Convert External Images to Embedded Base64

Convert external image files referenced in markdown to embedded base64 data URLs for portability while maintaining readability.

When to Use

  • Converting Obsidian vault notes to portable markdown
  • Removing external image dependencies
  • Creating self-contained markdown documents
  • Migrating between note-taking systems

Quick Start

bash
cd /home/ye/p/MyAgentSkills/convert-external-images/scripts
./convert_images.sh /path/to/markdown/file.md

Process Overview

  1. Backup - Creates .backup file before changes
  2. Detection - Finds Obsidian-style ![[image.png]] references
  3. Conversion - Converts images to base64, uses reference-style syntax
  4. Placement - Puts base64 definitions at end of file for readability
  5. Verification - Confirms all conversions succeeded
  6. Cleanup - Optional deletion of original image files (with confirmation)

Output Format

In main text (clean and readable):

markdown
![Descriptive alt text][embedded-image-1]

At end of file (base64 data):

markdown
[embedded-image-1]: <data:image/png;base64,iVBORw0KGgo...>

Features

  • ✓ Automatic MIME type detection (png, jpg, jpeg, gif, webp)
  • ✓ Reference-style syntax keeps main text clean
  • ✓ Base64 data at file end for readability
  • ✓ Backup creation before modifications
  • ✓ Verification step ensures success
  • ✓ Safe deletion with user confirmation
  • ✓ Handles missing image files gracefully
  • ✓ Obsidian-compatible reference syntax

Script Usage

See scripts/convert_images.sh --help for detailed options.

Benefits Over Inline Base64

Traditional inline:

markdown
![image](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...)

Makes text unreadable with giant base64 strings.

This approach:

  • Main text stays clean and readable
  • All base64 data relegated to file end
  • Standard markdown reference syntax
  • Works in Obsidian, VS Code, GitHub, etc.

Technical Details

  • Uses base64 -w 0 for single-line encoding
  • Python script handles file I/O and regex replacements
  • Sanitizes filenames to create clean reference IDs
  • Preserves original file permissions
  • Cross-platform compatible (Linux/macOS)