Nodes/KJNodes for ComfyUI/Ming-Image Prompt Builder KJ
ComfyUI Node Runs on cloud

Ming-Image Prompt Builder KJ

Draw your layout instead of hand-writing JSON captions

By kijai·Created 3 years ago·Updated 3 days ago· 3,521
Ming-Image Prompt Builder KJ
  • image
  • bboxes
  • prompt
  • preview
  • bboxes
  • width
  • height
◄width1024►
◄height1024►
◄aspect_ratio▾►
◄ambient_lighting►
◄image_style►
◄elements_data►
◄bg_brightness25►
◄import_modewhen empty►
◄output_formatpretty►
◄import_json►

The problem this solves

Ming-Image doesn't take a prompt. It takes a caption document: a canvas_settings block (aspect ratio, ambient lighting, image style) plus a list of layers, ordered back to front, and each layer carries a description, a hierarchy_and_relation line, a color_specs palette, and normalized cx, cy, w, h coordinates. That's a Figma frame described in JSON, and the model's own reference material ships it as a rewriter system prompt for an LLM to produce.

So the normal way to prompt Ming-Image is: get an LLM to write you structured JSON, then hope it got the coordinate format right. Or hand-edit nested JSON and find out three hundred milliseconds into a queue that you typo'd a bracket.

This node is a visual editor for that caption. Drag rectangles on a thumbnail canvas, type the description into each one, and the node assembles the JSON in the order and coordinate convention Ming-Image expects - which is the part humans reliably get wrong.

How it works

The node is a proper UI, not a widget farm. Drag on the canvas to draw a layer, click to select, alt-click to cycle overlapping layers, double-click to edit the description inline, right-click for the layer list (top of list = front of image) with delete, duplicate, lock and drag-to-reorder. The layers serialise into elements_data, and at execution the node builds the caption from them.

The geometry is where the care went in. Boxes are stored as fractions of the canvas and emitted as "cx: 0.500, cy: 0.500, w: 1.000, h: 1.000" - centre and size, clipped to the canvas, rounded the same way the front-end JS does it so editor and backend agree. Layers come out back to front: layer 01 is the bottom, usually a full-canvas background, the highest number the topmost overlay. If you've ever had a model put the subject behind the background, this ordering is why.

aspect_ratio follows width/height unless you set it to custom. In auto you get 16:9; in auto_with_size you get 16:9, 1360 × 768 px. It snaps to a table of common ratios within about 2%, then falls back to the reduced fraction.

The inputs and outputs that matter

Set these four and you're most of the way there:

  • width / height - 64 to 16384, step 16. The tooltip says it plainly: this is the canvas size and the pixel grid your px fields snap to.
  • ambient_lighting - the global lighting, mood and exposure line. This is where "warm late afternoon sun from the left" goes.
  • image_style - medium, rendering style, camera/lens, typography treatment. The other half of the look.

aspect_ratio is the dynamic combo (auto / auto_with_size / custom). image_style and ambient_lighting are plain multiline text.

The optional inputs are for plumbing: image is a reference shown as the editor background and behind the preview, import_json loads an existing caption into the editor, and bboxes seeds layers from pixel-space boxes when the editor has none.

import_mode decides what happens when you wire a caption in. when empty (the default) only seeds the editor while it has no layers - after that the editor wins, so your edits survive. always makes the wired JSON authoritative and propagate every time. That distinction is the single most likely thing to confuse you: if you're feeding captions in from a file and your edits keep getting ignored, or your updated file keeps getting ignored, this combo is why.

Outputs:

  • prompt (STRING) - the caption JSON. This goes to Ming-Image's prompt input.
  • preview (IMAGE) - a flat render of your boxes over the background, for eyeballing the layout. It is not a generation.
  • bboxes (BOUNDING_BOX) - the layer boxes, for feeding a masking or detection branch.
  • width / height (INT) - the canvas size, so you can wire the empty latent to match the caption instead of retyping numbers and drifting out of sync.
Ming-Image Prompt Builder KJ(prompt, width, height)
  prompt  → your Ming-Image text encode
  width   → Empty Latent (width)
  height  → Empty Latent (height)

Installing it

Same pack, same steps. Manager → search KJNodes → install → restart, or:

cd ComfyUI/custom_nodes
git clone https://github.com/kijai/ComfyUI-KJNodes
pip install -r ComfyUI-KJNodes/requirements.txt

KJNodes deliberately keeps its dependency list minimal - pillow, color-matcher, matplotlib, mss, opencv-python-headless - so this is not a node that drags in a second torch. That matters here because the pack tracks ComfyUI closely: its newer nodes are built on the current node API with a JS extension for the canvas, so an out-of-date ComfyUI is the usual reason the editor doesn't render. Update ComfyUI before you go bug-hunting.

Traps worth naming

Importing a caption resizes your canvas. Loading a caption reshapes width/height to its aspect ratio at roughly the same pixel count, unless you have an image connected - a connected image governs the aspect instead. That's deliberate, but it will surprise you if you wired a latent first.

Editing the source of a wired import and getting nothing. import_mode: when empty means the editor already "won". Switch to always, or clear the layers and let it re-seed. And don't dump the output JSON through a tool that re-sorts keys - the field order is deliberate.

CategoryKJNodes/text

Inputs (12)

NameTypeDefaultDescription
widthINT102464–16384Canvas width (also the pixel grid for the px coordinate field). Multiples of 16.
heightINT102464–16384Canvas height (also the pixel grid for the px coordinate field). Multiples of 16.
aspect_ratioCOMBOcanvas_settings.aspect_ratio: 'auto' derives it from width/height (e.g. '16:9'), 'auto_with_size' adds the pixel size (e.g. '16:9, 1360 × 768 px'), 'custom' is verbatim.
ambient_lightingSTRINGcanvas_settings.ambient_lighting: global lighting, mood and exposure.
image_styleSTRINGcanvas_settings.image_style: medium, rendering style, camera/lens, typography treatment.
elements_dataSTRINGSerialized layers from the editor (managed by the node UI).
bg_brightnessINT250–100Background image brightness % (managed by the node UI slider).
import_modeCOMBOwhen emptyHow a wired import_json is used: 'when empty' only seeds the editor while it has no layers (then the editor wins, so you can edit); 'always' makes the wired JSON authoritative so its changes always propagate to the output.
output_formatSTRINGprettyOutput JSON formatting (set via the editor toolbar): 'pretty' (default, indented like Ming-Image's example prompts) or 'compact' (single line).
imageoptIMAGEOptional reference image shown as the editor background (and behind the preview).
import_jsonoptSTRINGOptional: a full caption JSON. When connected, it loads into the editor and drives the output per 'import_mode'.
bboxesoptBOUNDING_BOX[object Object]Optional pixel-space boxes ({x, y, width, height}) used to seed the editor's layers when it has none. Ignored once layers exist.

Outputs (5)

NameTypeDescription
promptSTRING—
previewIMAGE—
bboxesBOUNDING_BOX—
widthINT—
heightINT—