Nodes/ComfyUI-XJNodes/Get Image from List (XJ)
ComfyUI Node

Get Image from List (XJ)

Pull one specific image out of a list by index — negatives work

By alexjx·Created 10 months ago·Updated 4 months ago· 0
Get Image from List (XJ)
  • image_list
  • image
index0

Once you've accumulated a list of images with the pack's list-building nodes, you'll eventually want one of them - the first, the last, or the one at some computed position. XJGetImageFromList is the index lookup for that list: give it the list and an index, and it returns the single image at that position.

It rounds out the ComfyUI-XJNodes image-list toolkit (empty list, append, length, slice, and this). The use cases are obvious once you see it: grab the last frame of an accumulation as the "hero" output, pull a specific render out of a batch for a dedicated save, or use a computed index to select by logic instead of by hand. It's the image equivalent of my_list[i], and it behaves the way you'd hope.

How it works

The node takes the list input (flagged list-aware, INPUT_IS_LIST), checks it's actually a list, and applies Python indexing. The details that matter:

  • Negative indexing works. index = -1 returns the last image, -2 the second-to-last, and so on - just like Python. This is genuinely handy for "take whatever we finished with."
  • Bounds are validated. If index is out of range for the list's size, it raises a clear error (Index ... out of range for list of size ...) instead of silently returning garbage.
  • An empty list refuses. You can't pull from nothing - the node errors with Cannot get image from empty list. Guard it with a length check if your list can legitimately be empty.

The index input is an INT (default 0, range -10000 to 10000), and the output is a single IMAGE (not a list), so it drops cleanly into anything expecting a plain image - a saver, a preview, a KSampler's image input.

The inputs and outputs

  • image_list (IMAGE, list) - where to look. Feed it from XJAppendImageList or any list-flagged source.
  • index (INT) - which position to grab; negative counts from the end.
  • Output: image (IMAGE) - the selected frame, with its batch dimension intact.

Installing it

Part of ComfyUI-XJNodes:

cd ComfyUI/custom_nodes
git clone https://github.com/alexjx/ComfyUI-XJNodes

then restart ComfyUI (or ComfyUI Manager → ComfyUI-XJNodes). No models, no dependencies.

Common issues

The two errors are the whole story: an out-of-range index, or indexing an empty list. Both raise loudly rather than failing silently, which is the good kind of behavior. One subtlety - if you feed this node a plain batch tensor instead of a genuine list, it'll error on the type check, so keep the list-flagged output of the pack's own nodes upstream. And remember the index is a widget you set per run; if you want a computed index (say, from a counter), wire it in rather than typing it.

CategoryXJNodes/Lists

Inputs (2)

NameTypeDefaultDescription
image_listIMAGE
indexINT0-10000–10000

Outputs (1)

NameTypeDescription
imageIMAGE