Nodes/ComfyUI-XJNodes/Image Preview Bridge
ComfyUI Node

Image Preview Bridge

Preview any image and paint a mask on it, right inside the workflow

By alexjx·Created 10 months ago·Updated 4 months ago· 0
Image Preview Bridge
  • images
  • image
  • mask
stop_if_emptytrue
image

ComfyUI's inpainting is powerful but the mask-making part is awkward: you generate a mask, save it somewhere, load it back in, and hope it lines up. XJImagePreviewBridge is the node that makes interactive masking feel native. It shows whatever image you feed it as a preview, lets you right-click it and open ComfyUI's mask editor to paint directly on the image, and then hands both the image and your freshly painted mask downstream - as a proper IMAGE and MASK pair - so the rest of the workflow just works.

It's from the ComfyUI-XJNodes pack, and it's honestly one of the more ambitious nodes in it: not a pure tensor utility, but a full frontend + backend bridge. If you've ever wished you could just paint the inpaint region instead of building masks with threshold nodes, this is the missing piece.

How it works

On each execution it saves the input image to ComfyUI's temp directory and shows it in the node, then writes the preview filename into a hidden widget. When you right-click and choose Open with Mask Editor, ComfyUI's clipspace editor loads that temp image, you paint, and the composite (image + alpha mask) is written back through the node's image string widget.

The clever part is the validation. The backend compares the unmasked regions of the saved composite against the current input image - the mask editor stores the original RGB with the mask in the alpha channel - so if the upstream image has changed since you painted, the node detects the mismatch and refuses to apply a stale mask. That's a genuinely thoughtful touch that prevents the classic "my mask is in the wrong place" failure. The mask is also converted to ComfyUI's convention (inverted alpha: 1 = masked). There's even a stop_if_empty toggle (default on) that blocks downstream execution when the mask is empty - so an unpainted image just stops instead of silently producing garbage.

Outputs are image (the passthrough) and mask (the painted mask). Inputs: images (IMAGE), stop_if_empty (BOOLEAN), and the image string widget the editor writes into.

Installing it

Part of ComfyUI-XJNodes:

cd ComfyUI/custom_nodes
git clone https://github.com/alexjx/ComfyUI-XJNodes

then restart ComfyUI (or ComfyUI Manager → ComfyUI-XJNodes). No models, no dependencies - it uses ComfyUI's own temp storage and mask editor.

Common issues

If the mask editor isn't appearing, check that you're right-clicking the node's preview area specifically, and that the pack's frontend files loaded (a restart after install fixes most cases). Stale-mask rejection is by design, not a bug: if you re-run with a new source image, repaint. And with stop_if_empty on, don't be confused when the workflow halts before sampling - that's the node telling you it has nothing to inpaint. It's the one node in this pack that has real interaction, and it earns its keep on any inpainting-heavy workflow.

CategoryXJNodes/image

Inputs (3)

NameTypeDefaultDescription
imagesIMAGE
stop_if_emptyBOOLEANtrue
imageoptSTRING

Outputs (2)

NameTypeDescription
imageIMAGE
maskMASK