Nodes/comfyui-kroki-wrapper/Render Diagram (Kroki)
ComfyUI Node

Render Diagram (Kroki)

Put a real diagram in your ComfyUI graph — no GPU, no API key

By Pantek59·Created 7 months ago·Updated 7 months ago· 0
Render Diagram (Kroki)
    • IMAGE
    diagram_codegraph TD A[Start] --> B[End]
    diagram_typemermaid
    width1024
    height768
    auto_croptrue
    kroki_urlhttps://kroki.io

    ComfyUI is the last place you'd expect to need a flowchart, and yet. Building a pipeline that documents itself, want a Mermaid architecture diagram sitting next to the image your model just made, or feeding diagrams into a vision model for QA? This node turns diagram code into a real IMAGE tensor, right inside the graph. Type markup in a text box, get a proper image to Save, Preview, or wire into anything that eats an IMAGE.

    The name deserves unpacking, because it's not what it looks like. This doesn't call an image-generation API and it needs no key. It wraps Kroki - the open-source "one endpoint for every diagram" service - which turns text markup into vector SVG for 22 different diagram languages: Mermaid, PlantUML, GraphViz, D2, Excalidraw, Wavedrom, DBML, and more. Whatever markup you can write, Kroki renders. The node is the bridge between that world and your canvas.

    How it works

    The mechanism is simple, and worth grounding in the actual code because the README has drifted (more below). The node:

    1. Compresses your diagram code (zlib deflate) and base64-encodes it.
    2. GETs {kroki_url}/{diagram_type}/svg/{encoded} - by default https://kroki.io.
    3. Gets SVG back.
    4. Renders it in headless Chromium via Playwright at your chosen resolution, then screenshots it to PNG.
    5. Auto-crops, composites onto white, converts to a float32 tensor.

    That Playwright step is the interesting bit. Many diagram types - Mermaid especially - use SVG foreignObject elements that embed real HTML/CSS, and only a full browser engine renders those correctly. That's why this pack drags in a ~300MB Chromium binary where a naive SVG-to-PNG converter wouldn't need it.

    The inputs that matter

    Only a handful, honestly:

    • diagram_code - the markup itself (multiline). Default is a trivial Mermaid graph.
    • diagram_type - 22 choices, mermaid default. Must match your code; picking the wrong language is the most common error.
    • width / height - 100–8192 px, default 1024×768; the browser viewport the diagram renders into.
    • auto_crop - on by default; trims the empty margin around the diagram so you don't get a mostly-white canvas.
    • kroki_url (optional) - point at a self-hosted Kroki instance here.

    Output is a single IMAGE tensor (batch, height, width, RGB). Straight into Save Image, a preview, or any downstream vision step.

    Install

    ComfyUI Manager - search for the pack title, comfyui-kroki-wrapper - install, restart. Or the manual route:

    cd ComfyUI/custom_nodes
    git clone https://github.com/Pantek59/comfyui-kroki-wrapper
    

    then restart ComfyUI. Two things to know first. The requirements.txt is mild - numpy, torch, Pillow, requests, playwright - nothing exotic. But on the first launch after install, if Playwright isn't present the module itself runs pip install playwright and playwright install chromium at import time. That's a ~300MB browser download, so the first start is slow; after that it's snappy. It's import-time code execution too - arbitrary Python on load, no sandbox - though the pack is small and readable, with no API-key handling to worry about (the usual malware vector).

    Where people get burned

    • README vs code drift. The README still documents background_color and custom_bg_color inputs and an ImageMagick step. All of that is gone in the current code - the latest commit is literally "Remove custom background color support; default to white." Today you get a white background and auto_crop instead. If a workflow you grabbed references the old inputs, it's stale; update it.
    • "Failed to render diagram via Kroki" - wrong diagram_type, a syntax error in your markup, or no internet. Try the same code on kroki.io directly to isolate which.
    • "Failed to render SVG using Playwright" - the Chromium binary is missing or the system lacks libraries Chromium needs (fonts and friends on bare Linux). Re-run pip install playwright && playwright install chromium.
    • Privacy. The default route sends your diagram code to kroki.io - fine for docs, dumb for confidential architecture. Self-host instead:
    docker run -d -p 8000:8000 yuzutech/kroki
    

    and set kroki_url to http://localhost:8000. That also makes the whole thing work offline.

    Should you install it?

    If you ever need a rendered diagram inside a workflow - docs, diagram-to-vision pipelines, slide assets - this is the mainstream way, and it's free. If you never need a diagram in a graph, it's a ~300MB paperweight. There's essentially zero community chatter about it (one show-and-tell thread in the corpus), so you're on your own - but the pack is tiny, the failure modes are legible, and Kroki itself is battle-tested. The one genuinely annoying part is the Chromium download on first launch.

    Categoryimage/generation

    Inputs (6)

    NameTypeDefaultDescription
    diagram_codeSTRINGgraph TD A[Start] --> B[End]
    diagram_typeCOMBOmermaid22 options: mermaid, plantuml, graphviz, blockdiag, seqdiag, actdiag, +16
    widthINT1024100–8192
    heightINT768100–8192
    auto_cropBOOLEANtrue
    kroki_urloptSTRINGhttps://kroki.io

    Outputs (1)

    NameTypeDescription
    IMAGEIMAGE