🔢 智绘_多图片开关
A picture selector that won't feed you a dead input
- image1
- image2
- 🖼️ 图像
- ℹ️ 信息
- 🔢 索引
- 📊 总数
A switch node picks one of several inputs and passes it through. That's a one-line job in most plumbing packs - but the boring version breaks when the slot you selected is empty. This one, ZH_ImageSwitch ("🔢 智绘_多图片开关"), is the version that refuses to hand you nothing: if the number you pick has no image behind it, it grabs the next live one instead.
It comes from ComfyUI-ZhiHui, a Chinese-language utility pack that absorbed several nodes from Dapao-Toolbox (the author's own guide credits it directly). Obscure in the English community - zero mentions in the corpus - but the behavior is all visible in the source.
How it works
You get up to 20 image inputs (image1, image2, …; the frontend shows two by default and reveals more as you connect them). A 🎯 编号 widget picks which to output. Then two safety toggles change the failure behavior:
- ⏭️ 跳过空图片 (on by default) - if the selected slot is unconnected, it scans forward for the next connected input instead of returning nothing. This is the killer feature: you can leave slots 2, 4, and 6 empty and the node still behaves.
- 🔄 循环模式 - off by default. With it on, picking an index past the last connected input wraps around to the first, so a counter feeding it 1→2→3→4→5 loops cleanly over three real images.
Without either toggle, out-of-range picks clamp to the nearest connected slot. The node also declares IS_CHANGED returning NaN, the classic "always rerun me" hook from the plumbing layer - important here, because a switch you're flipping interactively should never be served from the cache.
The inputs and outputs that matter
- 🎯 编号 - 1–20, the slot to output. Note it's 1-based, not 0-based; that trips up people coming from Python indexing.
- ⏭️ 跳过空图片, 🔄 循环模式 - the two toggles above.
- image1 … image2 - optional IMAGE inputs, dynamic up to 20.
Outputs: 🖼️ 图像 (the chosen IMAGE), ℹ️ 信息 (a status string telling you which slot won), 🔢 索引 (the actual selected index), and 📊 总数 (how many inputs are connected). The index output is the sleeper useful one - wire it into filename logic so your output name tracks which image got picked.
Install
cd ComfyUI/custom_nodes
git clone https://github.com/zhuyungen/ComfyUI-ZhiHui.git
Restart ComfyUI. No models, no heavy deps - just the pack's base torch/numpy/Pillow. ComfyUI Manager search "ComfyUI-ZhiHui" also works.
Where people get burned
Two things. First, if no images are connected at all it returns None for the image output rather than a black frame - downstream nodes get a null and throw, so don't treat this as a universal blank-safety net. Second, the "skip empty" search walks forward from the selected slot; if you pick a high number with only low slots filled, it lands on the nearest lower connected image, which can silently surprise you. If you want a strict 1:1 mapping between the selector and real images, keep the slots contiguous.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| 🎯 编号 | INT | 11–20 | 选择要输出的图片编号(1-20) |
| ⏭️ 跳过空图片opt | BOOLEAN | true | 如果选中的图片为空,自动使用下一张有效图片 |
| 🔄 循环模式opt | BOOLEAN | false | 当索引超出范围时,循环回到第一张图片 |
| image1opt | IMAGE | 第1张输入图片(可选) | |
| image2opt | IMAGE | 第2张输入图片(可选) |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| 🖼️ 图像 | IMAGE | — |
| ℹ️ 信息 | STRING | — |
| 🔢 索引 | INT | — |
| 📊 总数 | INT | — |