Text Condition Switch (YC)
Pick between two images based on a text match — the loop workflow's cheap branch
- image_a
- image_b
- image
- is_matched
Compare two strings; if they match, pass image_a through, otherwise pass image_b. It's the image-routing cousin of the pack's Mask Condition Switch - same string-comparison core, different data type, plus a boolean output so you can branch on the result elsewhere in the graph. If you've seen one, you've seen the pattern; the interesting part is where you'd actually put it.
What it's actually for
Per-iteration image selection in batch or loop workflows. The workflow carries text per pass - a filename, a tag, a value from a CSV or wildcard - and the image you want to feed downstream depends on that text. "If the current tag says day, use the daylight version; otherwise use the night version." That's this node. It's also a cheap way to force a branch: match on something and swap the entire input image for a placeholder, a mask preview, or a different crop.
How it works
Exact string comparison. input_text is tested against preset_text, with case_sensitive deciding whether case matters. On match, output image_a; otherwise image_b. is_matched carries the boolean regardless, so you can use the node as a pure text comparator even when you don't care about the image output.
The empty-branch behavior is the thing to remember: if the branch you need isn't connected, it returns a 1×1 black image rather than failing. That keeps the graph alive but can silently wreck downstream nodes that assume real dimensions. And the comparison is exact - trailing whitespace or a line break makes a visibly identical string fail the test.
Inputs and outputs
- input_text - the text under test
- preset_text - what it's compared against
- case_sensitive - default on
- image_a - passed when matched
- image_b - passed when not matched
Outputs: the chosen image and the is_matched boolean.
Install
Part of ComfyUI-YCNodes. ComfyUI Manager → search "ComfyUI-YCNodes" → install, restart, or:
cd ComfyUI/custom_nodes
git clone https://github.com/yichengup/ComfyUI-YCNodes
Standard deps (torch, numpy, pillow, opencv-python, scipy), no model downloads.
Where people get burned
- The 1×1 black fallback. Both branches optional, and an unconnected one silently returns a 1×1 image. If your downstream suddenly sees a black pixel instead of a photo, this is the usual suspect.
- Exact match, spaces and all. The comparison is
==, not "contains" and not trimmed. Sanitize text before it arrives, or matches you expect will quietly fail. - Expecting it to branch more than two ways. Two inputs, one test. For many-way image selection, use an index switch instead.
It's a two-image router with a string condition - a small piece, but the kind of thing that turns a manual "swap the input by hand" workflow into one that decides for itself.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| input_text | STRING | 输入文本,将与预设文本比较 | |
| preset_text | STRING | 预设文本,用于与输入文本比较 | |
| case_sensitive | BOOLEAN | true | 是否区分大小写 |
| image_aopt | IMAGE | 当输入文本与预设文本匹配时输出的图像 | |
| image_bopt | IMAGE | 当输入文本与预设文本不匹配时输出的图像 |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| is_matched | BOOLEAN | — |