Autonomous Mermaid to Flow-Animated GIF Converter
mermaid2gif is a fully autonomous, headless system that converts Mermaid diagrams into flow-animated GIFs. The system uses LangGraph for orchestration, LiteLLM for LLM interactions, Playwright for browser automation, and FFmpeg for high-quality media processing.
Key Features:
- π€ Fully Autonomous: Zero manual interaction required
- π― Headless Execution: CI/CD safe
- π Seamless Loops: "Buffered Recording" technology eliminates blank frames
- π¬ Flow Animation: Path-based animation for all supported diagram types
- π Smart Viewport: Auto-crops to diagram size (no excess white space)
- π High Quality: Sharp output with floyd_steinberg dithering and full palette generation
- π HD Sequence Diagrams: Specialized rendering configuration for crisp, readable text
Supported Diagram Types:
- β Flowcharts (TD/LR)
- β Sequence Diagrams
- β Class Diagrams
- β State Diagrams
- β ER Diagrams (Entity-Relationship)
The system is implemented as a Directed Cyclic Graph (DCG) using LangGraph:
- Orchestration: LangGraph
- LLM Interface: LiteLLM (Groq / OpenRouter)
- Rendering: Native Mermaid.js (via Playwright)
- Animation: JavaScript Path-Based Calculation
- Browser Control: Playwright (Chromium)
- Media Processing: FFmpeg (Palette-based encoding)
- Configuration: Pydantic Settings
- Python 3.11+
- FFmpeg (must be in system PATH)
- Clone the repository:
git clone https://github.com/rsrini7/mermaid2gif.git
cd mermaid2gif- Install dependencies:
pip install -e .
playwright install chromium- Configure environment:
cp .env.example .env
# Edit .env and add either GROQ_API_KEY (Recommended) or OPENROUTER_API_KEY# Convert natural language to GIF
python -m src.main "Create a flowchart showing user authentication flow"
# Convert Mermaid code directly
python -m src.main "graph TD; A[Start] --> B{Check}; B -->|Yes| C[OK];"# Read from file
python -m src.main --input-file diagram.mmd
python -m src.main -i diagram.mmd
# Specify output path
python -m src.main "graph TD; A-->B" --output my-diagram.gif
python -m src.main -i diagram.mmd -o output/result.gif
# Enable verbose logging
python -m src.main "Create a sequence diagram" --verbose
python -m src.main -i diagram.mmd -v
# Combine options
python -m src.main -i input.mmd -o output.gif -vAvailable Options:
-i, --input-file: Path to file containing Mermaid diagram code-o, --output: Output path for the generated GIF (default: auto-generated in./output/)-v, --verbose: Enable verbose logging for debugging
All configuration is managed through environment variables or .env file.
GROQ_API_KEY: Groq API Key (Recommended for speed/cost). Must start withgsk_.OPENROUTER_API_KEY: OpenRouter API Key. Must start withsk-or-.
| Variable | Default Value | Description |
|---|---|---|
LITELLM_MODEL |
groq/llama-3.3-70b-versatile |
LLM model via LiteLLM |
DEFAULT_ANIMATION_DURATION |
5.0 |
Animation duration in seconds |
DEFAULT_FPS |
30 |
Frame rate for GIF output |
VIEWPORT_WIDTH |
1920 |
Browser viewport width |
VIEWPORT_HEIGHT |
1080 |
Browser viewport height |
LOG_LEVEL |
INFO |
Logging level (DEBUG, INFO, WARNING, ERROR) |
mermaid2gif/
βββ src/
β βββ agents/
β β βββ __init__.py
β β βββ fixer.py # Mermaid syntax repair agent
β β βββ intent.py # Text-to-Mermaid conversion agent
β βββ core/
β β βββ __init__.py
β β βββ config.py # Pydantic configuration
β β βββ exceptions.py # Custom exception hierarchy
β β βββ graph.py # LangGraph orchestration
β β βββ state.py # Shared graph state
β βββ engine/
β β βββ __init__.py
β β βββ animation_applicator.py # JS path-based animation
β β βββ capture_controller.py # Playwright video capture
β β βββ ffmpeg_processor.py # FFmpeg transcoding & optimization
β β βββ mermaid_renderer.py # Native Mermaid.js rendering
β β βββ mermaid_validator.py # Syntax validation
β βββ utils/
β β βββ __init__.py
β β βββ logger.py # Structured logging
β βββ __init__.py
β βββ main.py # CLI entry point
βββ tests/
β βββ mocks/
β βββ __init__.py
β βββ test_smoke.py # Mock-based end-to-end test
βββ .env.example
βββ Dockerfile
βββ pyproject.toml
βββ README.md
βββ REQUIREMENTS.md
- No External Dependencies: Bypassed Draw.io completely. Rendering is pure local Mermaid.js.
- Headless Only: No manual interaction required.
- Deterministic: Same input always produces same output.
- Buffered Capture: Recording time is
Duration + 2sto ensure clean loops. - Smart Viewport: Two-phase capture (measure β record) auto-crops to diagram size with 40px padding.
This project was developed with contributions from:
- Srinivasan Ragothaman - Project Creator & Lead Developer
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
MIT License - see LICENSE file for details