A Python utility that converts Mermaid diagram files to high-resolution PNG images with optimized settings and transparent backgrounds.
- Batch conversion of
.mmd
files to PNG format - High-resolution output with customizable scaling
- Transparent background support
- Optimized diagram settings for better readability
- Configurable font sizes and spacing
- Error handling and detailed logging
- Python 3.6 or higher
- Node.js and npm installed
- Clone this repository:
git clone https://github.com/doomL/mermaid-bulk-converter
cd mermaid-bulk-converter
- Install Python dependencies:
pip install pathlib
- Install Mermaid CLI:
Method 1: Local Installation (Recommended)
npm install -g @mermaid-js/mermaid-cli
Run the script from the command line:
python mermaid-bulk-converter.py -i /path/to/input/directory -o /path/to/output/directory -s 3.0
-i, --input
: Directory containing Mermaid (.mmd
) files-o, --output
: Directory where PNG files will be saved-s, --scale
: Scale factor for PNG resolution (default: 3.0)
- Create a Mermaid diagram file
flowchart.mmd
:
graph TD
A[Start] --> B{Decision}
B -->|Yes| C[OK]
B -->|No| D[Cancel]
- Convert to PNG:
python mermaid-bulk-converter.py -i ./diagrams -o ./output -s 4.0
The script uses optimized default settings for:
- Font size and family
- Diagram padding and spacing
- Node layout and dimensions
- Background transparency
- Device scale factor
These settings can be modified in the config
dictionary within the script.
The script includes comprehensive error handling:
- Creates missing output directories
- Reports conversion errors for individual files
- Cleans up temporary files
- Provides detailed error messages
MIT License
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request