PD Image List Sort
PD Image List Sort — be honest with yourself about what this one can actually sort
- images
- sorted_images
Sorting an image batch by the content you loaded is one of those jobs that sounds trivial and turns out to be a trap, because an IMAGE tensor on the wire carries no filenames. The batch is just frames - whatever order the loader produced. PD Image List Sort is the pack's answer, with a sort_method of number, alphabet, or natural, plus a reverse_order toggle.
Here's the honest part, and it's the whole reason this article exists: the plain version has no filename input. With no metadata to sort on, it derives a name from the frame index - image_0000, image_0001, and so on - which means sorting by "number" on those auto-names is a no-op (they're already in index order), and "natural" is likewise. You'll get the batch back in the same order, sorted or not.
So when is this node actually useful? When the upstream node has already baked sorting intent into the batch order - or, more practically, when you're using it as a deterministic re-orderer with reverse_order to flip a batch. The real sorting lives in its sibling, PD Image List Sort (With Metadata), which accepts a filename list. That's the one to reach for.
How it works (mechanism anyway)
The machinery is decent: number extracts the first integer from a name and sorts with zero-padding awareness (so 001 orders before 1), alphabet takes the first letter sequence, and natural splits digits from text and compares numerically within them - the classic natsort key. reverse_order flips the final result. If the sort key extraction fails on any frame, it warns and falls back to the original index instead of crashing.
The inputs that matter
- images (
IMAGE) - the batch. - sort_method -
number/alphabet/natural. - reverse_order (
BOOLEAN, default off).
One output: sorted_images (IMAGE).
The take
Don't fight it. If you need filename-aware sorting, use the With-Metadata variant in the same pack and feed it the filenames (one per line, in the batch's current order) - that version does exactly what you'd hope, including the padding-aware number sort that keeps 001 before 10. If you just want to reverse a batch, reverse_order here works fine and avoids adding a metadata dependency.
Install
ComfyUI Manager: search PDuse (repo 7BEII/Comfyui_PDuse), install, restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/7BEII/Comfyui_PDuse
cd Comfyui_PDuse
pip install -r requirements.txt
Restart and it appears as PD Image List Sort under PDuse/Image. One-line summary: it's the frontman, the With-Metadata node does the real work.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| images | IMAGE | — | |
| sort_method | COMBO | 3 options: number, alphabet, natural | |
| reverse_order | BOOLEAN | false | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| sorted_images | IMAGE | — |