Nodes/LF Nodes/Switch Image
ComfyUI Node

Switch Image

The lazy image switch that only runs the branch you pick

By lucafoscili·Created 2 years ago·Updated 2 years ago· 50
Switch Image
  • on_true
  • on_false
  • ui_widget
  • image
  • image_list
booleanfalse

The first time someone explains ComfyUI switches, you nod along and think "cool, an if statement." Then you build one and realize most of them evaluate both inputs anyway. SwitchImage from LF Nodes doesn't do that, and it's the one good reason to reach for it over a plain Image Switch in a big workflow.

Here's the trick: its two image inputs are lazy. The node tells ComfyUI which of on_true or on_false to actually compute, and the other branch never runs. That means you can park two heavy pipelines behind it - say, a hires-fix path and a straight-to-output path, or a ControlNet branch and a plain one - flip one boolean, and only the branch you picked costs you GPU time. For A/B testing, that's the difference between two renders and one.

How it works is simple: feed an image tensor into on_true and another into on_false, then set the boolean widget (or wire it from a RandomBoolean, a slider, anything that emits a BOOLEAN). True returns on_true, false returns on_false. That's the whole mechanism - no blending, no fallback, just a ternary in node form.

The outputs matter more than you'd think. It returns both a single image and an image_list (a list typed output of the same thing), so it drops cleanly into either a batched sampler setup or a plain SaveImage. Both are the selected image; you just pick the shape your downstream node wants.

The inputs you actually set:

  • boolean - the condition; a checkbox you flip or a wire from another node.
  • on_true / on_false - the two candidate images.

One honest caveat: because the unselected input is never computed, anything on that side of the graph that you wanted to always run (a save node, a metric) silently won't. That's the feature, but it surprises people the first time.

Installing LF Nodes - it's the same pack for all the LF nodes:

  • ComfyUI Manager → search "LF Nodes" → install → restart, or
  • cd ComfyUI/custom_nodes && git clone https://github.com/lucafoscili/comfyui-lf then restart.

Note the repo is now in legacy mode: it's frozen at its last stable release while development moved to lucafoscili/lf-nodes. It still works fine, and this node is one of the many whose name and behavior carry over unchanged. It needs no extra model downloads - only the pack's usual dependencies (numpy, Pillow, opencv-python).

Where people get burned: dragging the wrong output. Grab image for a single tensor and image_list for batching; if a node rejects the connection, try the other. And remember the lazy-input behavior when you build a toggled workflow - it's the reason to use this switch, but only if you want the loser branch skipped.

Category✨ LF Nodes/Logic

Inputs (4)

NameTypeDefaultDescription
on_trueIMAGEValue to return if the boolean condition is true.
on_falseIMAGEValue to return if the boolean condition is false.
booleanBOOLEANfalseBoolean condition to switch between 'on_true' and 'on_false' values.
ui_widgetoptKUL_PROGRESSBAR[object Object]

Outputs (2)

NameTypeDescription
imageIMAGE
image_listIMAGE