mermaid-to-gif
zc277584121/marketing-skills
Convert Mermaid diagrams to animated GIFs with context-aware animation styles (progressive, highlight-walk, pulse-flow, wave).
What is mermaid-to-gif?
Transforms Mermaid code blocks from .mmd or .md files into animated GIFs with four customizable animation styles. Use this when you need to visualize diagrams dynamically for presentations, documentation, or social media, and want to match animation style to the semantic meaning of each diagram.
- Extract and convert Mermaid code blocks from .mmd files and markdown documents
- Apply four animation styles: progressive (sequential activation), highlight-walk (spotlight effect), pulse-flow (data flow dashes), and wave (brightness ripple)
- Batch-process multiple files with configurable output directory
- Customize appearance with themes, colors, padding, scale, and custom CSS
- Generate looping or one-time GIFs with adjustable duration, FPS, and hold frames
How to install mermaid-to-gif
npx skills add https://github.com/zc277584121/marketing-skills --skill mermaid-to-gif- FFmpeg installed and in PATH
- Python 3.8 or higher
- Playwright: pip install playwright && playwright install chromium
How to use mermaid-to-gif
- 1.Install the skill using: npx skills add https://github.com/zc277584121/marketing-skills --skill mermaid-to-gif
- 2.For a single .mmd file, run: python <skill-root>/scripts/mermaid_to_gif.py diagram.mmd
- 3.For markdown files with mermaid blocks, run: python <skill-root>/scripts/mermaid_to_gif.py document.md -o ./images/
- 4.Read the markdown context around each mermaid block to choose the appropriate animation style (pipeline → pulse-flow, architecture → progressive, tutorial → highlight-walk, reference → wave)
- 5.Replace original mermaid code blocks in markdown with image references: 
- 6.Customize with flags like --style, --theme, --duration, --fps, --scale, and --custom-css as needed
Use cases
- Convert architecture diagrams to progressive animations showing layer-by-layer activation
- Transform data pipeline flowcharts to pulse-flow GIFs showing data movement
- Create step-by-step tutorial visuals using highlight-walk spotlight effect
- Batch-convert all mermaid blocks in documentation to animated GIFs for web display
- Generate retina-quality GIFs for presentations with custom styling and dark themes
- Technical writers creating animated documentation
- Architects presenting system designs with progressive reveals
- Data engineers visualizing ETL and pipeline flows
- Educators building interactive tutorials
- Content creators needing animated diagrams for social media
mermaid-to-gif FAQ
Read the markdown context around each diagram. Use pulse-flow for data pipelines, progressive for architecture/hierarchy, highlight-walk for step-by-step processes, and wave for simple reference diagrams. The skill includes a decision guide matching context clues to recommended styles.
Yes. Run: python <skill-root>/scripts/mermaid_to_gif.py document.md -o ./images/ This extracts all ```mermaid code blocks and generates one GIF per block.
Process the file multiple times with different styles, extracting specific blocks each time. Or process the whole file with a sensible default, then re-run individual blocks that need different treatment using the -s/--style flag.
Use --scale 1 for lower resolution, reduce --duration, lower --fps, or use --theme dark with a dark background. The wave style also tends to produce smaller files than progressive.
Yes. Use --theme (default, dark, forest, neutral), --bg for background color, --padding for spacing, and --custom-css to pass a CSS file for advanced styling like rounded nodes or thicker edges.
Full instructions (SKILL.md)
Source of truth, from zc277584121/marketing-skills.
name: mermaid-to-gif description: Convert Mermaid code blocks in .mmd or .md files to animated GIFs with customizable animation styles (progressive, highlight walk, pulse flow, wave).
Skill: Mermaid to GIF
Convert Mermaid diagrams into animated GIFs with rich animation effects. Supports .mmd files and extracting ```mermaid code blocks from .md files.
Prerequisites: FFmpeg, Python 3.8+, Playwright (
pip install playwright && playwright install chromium)
When to Use
- The user wants to convert Mermaid diagrams to animated GIFs
- The user has
.mmdfiles or.mdfiles containing mermaid code blocks - The user needs animated visuals for presentations, documentation, or social media
- The user wants to batch-convert all mermaid blocks in a document
Context-Aware Style Selection
IMPORTANT: When converting mermaid blocks from .md files, read the surrounding markdown context to choose the most appropriate animation style for each diagram. Do NOT blindly apply the same style to all blocks.
Decision Guide
- Read the markdown text around each mermaid block — understand what the diagram is illustrating
- Match the style to the semantic meaning:
| Context Clue | Recommended Style | Reasoning |
|---|---|---|
| Data pipeline, ETL flow, request/response path | pulse-flow | Flowing dashed lines convey data movement |
| Architecture layers, org chart, hierarchy | progressive | Elements activate layer-by-layer |
| Step-by-step process, tutorial walkthrough | highlight-walk | Spotlight guides the reader through each step |
| System overview, title diagram, simple reference | wave | Brightness ripple adds life without distraction |
| Sequence diagram with message flow | progressive | Messages activate one by one in conversation order |
| Class/ER diagram (reference/static) | progressive or wave | Structure lights up or gets a subtle ripple |
-
Consider special handling:
- If the surrounding text says "data flows from A to B", use
pulse-floweven for a simple flowchart - If the text describes "three layers" or "two tiers", use
progressiveto activate layer-by-layer - If the diagram is decorative or supplementary, use
waveto keep it simple - For very large or complex diagrams, prefer
waveor shorter--durationto keep GIF size reasonable
- If the surrounding text says "data flows from A to B", use
-
Per-block style override: When batch-processing a
.mdfile, you may need to run the script multiple times with different styles, extracting specific blocks. Or process the whole file with a sensible default and re-run individual blocks that need different treatment.
Example: Context-Aware Processing
## Data Ingestion Pipeline ← context: "pipeline" → pulse-flow
[mermaid block: graph LR with ETL stages]
## System Architecture ← context: "architecture" → progressive
[mermaid block: graph TD with layers]
## Quick Reference ← context: "reference" → wave
[mermaid block: simple diagram]
Default Workflow
Single .mmd file
python <skill-root>/scripts/mermaid_to_gif.py diagram.mmd
Markdown file with mermaid blocks
python <skill-root>/scripts/mermaid_to_gif.py document.md -o ./images/
This extracts all ```mermaid code blocks and generates one GIF per block.
Multiple files
python <skill-root>/scripts/mermaid_to_gif.py *.mmd -o ./gifs/
python <skill-root>/scripts/mermaid_to_gif.py doc1.md doc2.md -o ./gifs/
Replacing mermaid blocks in markdown
After generating GIFs, replace the original ```mermaid code blocks with image references:

Use descriptive alt text based on the diagram content. The image path should be relative to the markdown file.
Animation Styles
All styles keep the diagram fully visible from frame 1 — no elements start hidden or fade in from zero. Every style adds motion while the user can see the complete diagram structure at all times.
| Style | Effect | Best For |
|---|---|---|
progressive (default) | All elements start dimmed (25% opacity), activate sequentially to full brightness; edges draw in with stroke animation | Flowcharts, architecture, hierarchy |
highlight-walk | All elements start dimmed (15%); a spotlight with blue glow moves through each element, leaving visited ones bright | Step-by-step process, tutorials |
pulse-flow | All elements fully visible; edges become flowing dashed lines (uniform dash size and speed) | Data flow, pipelines, request paths |
wave | All elements fully visible; a brightness pulse + blue glow ripple sweeps through elements sequentially | Simple diagrams, overviews, reference |
Animation Details
- progressive: Elements start at 25% opacity (diagram structure always visible). Nodes, edges, and labels activate in interleaved order (node → edge → node → edge) following flow direction. Edges use stroke-dashoffset to draw in visually. Activation is fast (8% of total duration per element).
- highlight-walk: All elements start at 15% opacity. A spotlight (with blue glow) moves through elements in order, leaving visited elements at 90% opacity. The whole diagram is visible as a "ghost" before the spotlight reaches each element.
- pulse-flow: All elements at full opacity. Edge paths get a uniform dashed pattern (10px dash + 6px gap) that flows at a fixed speed (200px/cycle), so all edges animate at the same pace regardless of length.
- wave: All elements at full opacity. A brightness pulse (1.0→1.4→1.0) with blue glow sweeps through elements sequentially. No position changes — purely a visual ripple effect.
Common Options
| Flag | Default | Description |
|---|---|---|
-o, --output-dir | Same as input | Output directory for generated GIFs |
-s, --style | progressive | Animation style (see table above) |
--fps | 10 | Frames per second |
--duration | 4.0 | Animation duration in seconds |
--hold | 1.0 | Hold last frame before looping (seconds) |
--theme | default | Mermaid theme: default, dark, forest, neutral |
--bg | #ffffff | Background color (hex) |
--padding | 40 | Padding around diagram in pixels |
--scale | 2 | Render scale factor (2 = retina quality) |
--custom-css | — | Path to custom CSS file |
--no-loop | — | Play GIF once instead of looping |
Examples
# Dark theme with faster animation
python <skill-root>/scripts/mermaid_to_gif.py arch.mmd --theme dark --bg "#1a1a2e" --duration 3
# High FPS for smoother animation
python <skill-root>/scripts/mermaid_to_gif.py flow.mmd --fps 15 --duration 5
# Batch convert all mermaid blocks from a doc
python <skill-root>/scripts/mermaid_to_gif.py README.md -o ./images/
# Custom CSS for special effects
python <skill-root>/scripts/mermaid_to_gif.py diagram.mmd --custom-css my-style.css
# No loop, suitable for one-time playback
python <skill-root>/scripts/mermaid_to_gif.py intro.mmd --no-loop --duration 6
# Lower resolution for smaller file size
python <skill-root>/scripts/mermaid_to_gif.py diagram.mmd --scale 1
Custom CSS
Create a CSS file to customize the appearance of the diagram during animation:
/* Rounded nodes with shadow */
.node rect {
rx: 10;
filter: drop-shadow(2px 2px 4px rgba(0,0,0,0.3));
}
/* Thicker edge lines */
.edgePath path {
stroke-width: 2.5;
}
/* Custom background for actors (sequence diagram) */
.actor {
fill: #e8f4f8;
}
Pass it via --custom-css:
python <skill-root>/scripts/mermaid_to_gif.py diagram.mmd --custom-css my-style.css
How It Works
- Parse input — extract Mermaid code from
.mmdor.mdfiles - Generate HTML — embed Mermaid.js (CDN) + animation JS/CSS in a self-contained HTML file
- Render — Mermaid.js renders the diagram to SVG in headless Chromium via Playwright (with 2x device scale for retina quality)
- Scale — small SVGs are automatically scaled up to minimum 700px CSS width for readability
- Animate — JS animation engine exposes
setProgress(t)for frame-by-frame control (t: 0→1). Elements are collected, sorted by position (respecting LR/TB direction), and animated in interleaved node-edge order - Capture — Playwright takes a screenshot at each frame step
- Assemble — FFmpeg two-pass palette encoding (palettegen → paletteuse with Floyd-Steinberg dithering)
Important Notes
- Internet required: Mermaid.js is loaded from CDN at render time
- Supported diagram types: flowchart, sequence, class, state, ER, gitgraph, mindmap, pie, gantt, and more
- No hidden elements: all 4 styles keep the diagram visible from frame 1 — no waiting for elements to appear
- Fallback behavior: for unrecognized diagram types or when no animatable elements are detected, falls back to a whole-diagram opacity reveal
- Resolution: default scale=2 produces retina-quality images (~1400-1600px wide). Use
--scale 1for smaller files - GIF size: for very large outputs, reduce FPS to 8, shorten duration, use
--scale 1, or usewavestyle
Related skills
More from zc277584121/marketing-skills and the wider catalog.

mermaid-to-image
Convert Mermaid diagram code blocks to PNG images using mermaid.ink API.

raw-video-processing
Remove silent segments and speed up raw screen recordings with FFmpeg-based post-processing.

remove-ai-style
Remove AI-generated writing patterns to make text sound more natural and human-like in Chinese or English.

screenshot-compression
Compress PNG and JPEG screenshots in place using pngquant and jpegoptim while preserving format compatibility.

video-to-gif
Convert videos to multiple GIF variants with different quality/size tradeoffs for visual comparison.

git-commit-pr
Commit changes and create a pull request to the official upstream repo