Nodes/NN-custom-nodes/Image Preview Gate
ComfyUI Node

Image Preview Gate

A preview that doesn't explode when nothing's connected

By bandifiu·Created about a month ago·Updated about a month ago· 0
Image Preview Gate
  • image
  • image
width256
height256

Optional image inputs are a classic ComfyUI trap. You build a workflow with an optional slot - "upload a reference, or don't" - and the first time you run it without the reference, the downstream node chokes on None and the whole graph errors out. "Image Preview Gate" exists to keep that from happening: when no image is connected, it hands downstream a harmless black placeholder instead of nothing.

What it is

NNImagePreviewGate is a fallback node in the plumbing sense of the word - the KB's node-plumbing doc calls this the first-non-null shape, except here the "fallback" is a generated placeholder rather than another input. Per the README: "Provides a fallback preview image when no image is connected. Useful for optional image inputs in workflows." The image input is optional; the two size widgets, width and height, are the required ones.

How it works

Dead simple under the hood. If an image is connected, it passes straight through untouched - zero cost. If it's not, the node generates a black width×height image with the text "No preview" drawn in white across the middle, using PIL, and returns that as a normal image tensor. Nothing is trained, nothing is hallucinated, no model runs. It's a placeholder, on purpose.

The useful part is where it fits in a graph. Stick it in front of any node that has an optional image input you'd rather not wire - a reference slot on a ControlNet-style node, a style-reference input, a compositing input. When the upstream image is present you get the real pixels; when it's absent you get a clearly-labeled black box instead of a hard error. That "clearly-labeled" bit matters: a plain black fallback is indistinguishable from a genuinely black image, and you'd spend a confusing hour wondering why your composition is black. The "No preview" text exists so the fallback is obvious at a glance.

The inputs

  • width - 64–8192, default 256. Placeholder size (and thus the size downstream will receive) when no image is connected.
  • height - 64–8192, default 256.
  • image - optional. Connected = passthrough; unconnected = placeholder.

Single image output.

When to reach for it

Two workflows love this node. The first is anything with a genuinely optional reference: you want one saved workflow that works with or without a reference image, and you'd rather see "No preview" than a red error. The second is debugging - when you're building a branch and haven't wired the source yet, this node keeps the graph runnable so you can test the rest of the pipeline while the branch is still empty.

One honest caveat: this is a placeholder, and a 256×256 default one at that. If your downstream node does something size-sensitive (crops to match, composites over another image), a placeholder sized by whatever you set here can still cause surprises - that's not a bug in the node, it's the nature of "fake input." Set width/height to something sane for your pipeline, and expect to swap in real pixels before you trust any output downstream of the placeholder.

Installing

Part of bandifiu/ComfyUI-NN-custom-nodes:

cd ComfyUI/custom_nodes
git clone https://github.com/bandifiu/ComfyUI-NN-custom-nodes

Restart ComfyUI (or Manager → "NN-custom-nodes"). Deps: torch, numpy, pillow - no models, no downloads. GPL-3.0, V3 backend API, no classic registration dicts.

The gotcha to remember is the font fallback: it tries arial.ttf and silently falls back to PIL's default bitmap font if it's not found on your system (it usually isn't on Linux). Either way you get "No preview" text - it just looks slightly different - so don't panic if the placeholder text renders chunkier than the screenshots.

CategoryNN/image

Inputs (3)

NameTypeDefaultDescription
widthINT25664–8192
heightINT25664–8192
imageoptIMAGE

Outputs (1)

NameTypeDescription
imageIMAGE