Nodes/Custom Node Kit/图像列表位置替换 (Image List Replace)
ComfyUI Node

图像列表位置替换 (Image List Replace)

Swap one image in a list of mismatched refs — no resizing, no drama

By user2318·Created 6 months ago·Updated 9 days ago· 58
图像列表位置替换 (Image List Replace)
  • images
  • replace_images
  • images
◄start_index0►

The thing you actually want it for

Sooner or later you end up with a folder of reference images that aren't all the same size - a 360° turnaround batch, angles exported from different sessions, a couple of close-ups pulled off a phone. ComfyUI's IMAGE type is a batch: one tensor shaped [B, H, W, C] where every frame shares height and width, or the graph blows up downstream. The standard workaround is to resize everything, which is what you were trying to avoid.

That's the wall this node is for. ImageListReplaceAt works on an image list instead - the elements live side by side as separate tensors, each allowed its own dimensions, and the node sees the whole list in a single run. You pick a position, you hand it clean replacements, and it swaps them in. Item four can be 1024×1024 while item five is 1920×1080 and nobody complains.

The narrow case, spelled out: you have a set of refs, one is garbage, and you want a hand-picked version in slot 3 without re-exporting anything.

How the replacement actually works

Two things to know, and both are deliberate.

First, the list never grows. Replaced count is min(len(replace_images), len(images) - start_index). Five items, start_index=2, four replacements: items 3, 4 and 5 change and the fourth replacement is silently dropped. Feed two and item 5 is untouched.

Second, nothing is scaled, padded or resized - elements are swapped whole. That's the whole difference from the pack's BatchImageReplace, which works on same-size batches, takes a replace_count, offers overflow/underflow strategies and will happily rescale replacements to match. No such modes here: mismatched sizes are fine, and the output is a list, so whatever you wire into runs once per element.

The node declares INPUT_IS_LIST, so a plain same-size batch plugged in upstream gets split into individual frames automatically. One edge case: a "list" containing exactly one multi-frame batch is read as that batch and taken apart.

Inputs and the one output

You only have to think about one widget:

  • start_index - the 0-based slot where replacement begins. 0 replaces from the front, 2 starts at the third item.
  • images (optional) - the list being replaced. Leave it unwired and the node outputs nothing at all, quietly.
  • replace_images (optional) - the incoming list. Leave this one unwired and the target list passes straight through unchanged, which is handy: it means you can build the node into a workflow and enable the replacement later.

Output is a single images (IMAGE, list semantics). Because it's a list, downstream nodes execute once per element - a save or preview behind it now runs N times instead of once. Usually what you want; just don't blame the sampler for being twice as slow.

Installing it

The pack has no community footprint to speak of - one prolific author's personal toolkit, published in Chinese, covering video generation, pose handling and a pile of image plumbing. Good news for you: these list nodes have essentially no dependencies; torch and numpy are all they touch.

ComfyUI Manager: search for ComfyUI-CustomNodeKit and install. Or by hand:

cd ComfyUI/custom_nodes
git clone https://github.com/user2318/ComfyUI-CustomNodeKit.git
cd ComfyUI-CustomNodeKit
pip install -r requirements.txt

Then restart ComfyUI. One install note, because it'll surprise you otherwise: the pack's install.py runs on every startup and pip-installs groundingdino-py and transformers if they're missing. Those belong to its GroundingDINO/SDPose nodes, not this one, they're chunky enough that a first launch can sit a while, and failure isn't fatal - it prints a manual pip install line and carries on. On embedded installs with no working tkinter, that same file also fetches DLLs from NuGet into your interpreter directory. Slightly audacious, but it's what ships.

Where people get tripped up

  • "It output nothing." You wired replace_images but not images. An empty or unconnected target returns nothing, with no error and no output - by design, so a comment says an empty lane behaves exactly like an unplugged cable.
  • "My replacement didn't happen." Check start_index against the list length. Past the end, the node logs a warning and returns the target untouched.
  • "Extra images vanished." Working as intended - the list length is fixed. If you need the output to be longer, this is the wrong node.
  • "Downstream error about shapes." You wired this list output into something that demands a proper batch. Put ImageListToBatch in between.

None of these are bugs. They're the price of a node that keeps its promise: swap in place, resize nothing.

Categoryimage

Inputs (3)

NameTypeDefaultDescription
start_indexINT00–4294967295从列表第几个元素开始替换(0 = 第 1 个,1 = 第 2 个,以此类推)。List index to start replacing at (0 = first item).
imagesoptIMAGE要被替换的图像列表(列表语义:元素尺寸可不同)。未连接时不报错也不输出。Target image list (list semantics: elements may have different sizes). If not connected, nothing is output and no error is raised.
replace_imagesoptIMAGE用来替换的图像列表,按顺序填入 start_index 之后的对应位置;比剩余空间多出来的部分会被丢弃(不扩展列表)。未连接时原样透传目标列表。Replacement source list; items are written into the positions after start_index. Extra items are dropped (the list is never extended). If not connected, the target list is passed through unchanged.

Outputs (1)

NameTypeDescription
imagesIMAGE—