Nodes/ComfyUI-Light-Tool/Light-Tool: Get Images Count
ComfyUI Node

Light-Tool: Get Images Count

How many images are in this batch? Ask the tensor.

By ihmily·Created 2 years ago·Updated 4 months ago· 20
Light-Tool: Get Images Count
  • image
  • count

Light-Tool: GetImagesCount answers one question: how many images are sitting in this tensor right now? Feed it any IMAGE input and it returns the batch count. That's the entire job, and it's one of those tiny nodes that becomes surprisingly load-bearing once you're doing anything batch-oriented.

ComfyUI IMAGE tensors carry a batch dimension - a single "image" on the wire is often a stack of several, whether it came from a directory loader, a batch of generations, or a list built by a router. Knowing the count matters for loops, for deciding whether a node will process everything at once, and for sanity-checking that your batch didn't silently collapse to one frame.

How it works

The mechanism is almost insultingly simple: it reads the leading dimension of the tensor and returns it. len(image) on a shape (N, H, W, C) tensor gives N, which is exactly the number of images in the batch. No resizing, no re-encoding, no file I/O - it's a metadata read, instant and side-effect free.

Input: image (any IMAGE tensor). Output: count (wildcard type, but in practice a whole number).

Where you'll actually use it

  • Loop control. Feed the count into a loop or a router that needs to iterate once per image.
  • Batch sanity checks. A directory loader that was supposed to grab 20 files but returned 1 - this node tells you at a glance, and you can branch on it.
  • Conditional workflows. "If there's more than one image, split and process; if it's a single frame, take the fast path" - that branching needs the count as a number you can compare.

The honest take

Let's be real: this is a utility you'll reach for occasionally, not a node you build a workflow around. Its value is that it's there when you need a count as graph data. The alternative - guessing the batch size, hard-coding a loop length, or squinting at the tensor preview - is exactly the kind of fragile thing that breaks silently when your inputs change. Having the number as a first-class output you can wire into a comparison or a loop is genuinely more robust than any of those.

One caveat: the output is a wildcard (*) rather than a strict INT, so a downstream node that demands a concrete INT may want it run through the pack's ConvertNumType first. It's a two-second adapter, but it's a real foot-gun if you wire count straight into a node that rejects wildcards.

Install

Standard: ComfyUI Manager → search ComfyUI-Light-Tool, or clone into custom_nodes, pip install -r requirements.txt, restart. It's under ComfyUI-Light-Tool → image → other. Pure Python, no models, no dependencies beyond what ComfyUI already has.

CategoryComfyUI-Light-Tool/image/other

Inputs (1)

NameTypeDefaultDescription
imageIMAGE

Outputs (1)

NameTypeDescription
count*