Nodes/ComfyUI-JH-PixelPro/Compositing: Layer Flatten
ComfyUI Node

Compositing: Layer Flatten

The node that turns your layer stack back into a picture

By jetthuangai·Created 5 months ago·Updated 4 months ago· 5
Compositing: Layer Flatten
  • stack
  • IMAGE

The whole layer system in the ComfyUI-JH-PixelPro pack is a description until this node runs. JHPixelProLayerFlatten takes a LAYER_STACK and renders it back into a real IMAGE, compositing every layer in order - background first, then each added layer with its blend mode, opacity, fill, mask, and clipping applied, groups collapsed as they were built. Stack in, IMAGE out, done.

It's deliberately boring, and that's the point. You build your composition with JHPixelProLayerStackStart and JHPixelProLayerAdd (and maybe JHPixelProLayerGroup for nesting), and nothing is actually drawn until Flatten. That's a feature: you can build a stack, branch it, and flatten different branches into different images without rerunning anything upstream. The flatten is the only point where pixels get produced.

What you need to know

  • One input, one output. stack (LAYER_STACK) in, IMAGE out. That's the entire schema.
  • Empty stacks raise ValueError. The README calls it out, and it's the most common beginner stumble - if you disconnect the stack wire, or the stack's background never got created, flatten refuses rather than silently producing garbage. In practice it means "check your upstream wiring."
  • Order is preserved. The stack is immutable and ordered; layers composite in the order they were added. Reorder your graph, not the stack.
  • Non-destructive until the end. Nothing mutates - you can always add another layer and flatten again. This is the "non-destructive editing" story that ComfyUI's normal blend nodes never quite give you.

The output IMAGE is exactly the base stack size, because masks and layer images auto-resize to the background when they're added. Wire it into a PreviewImage or a SaveImage, or feed it into any downstream node - it's a normal IMAGE from here on out.

Install

ComfyUI Manager → search ComfyUI-JH-PixelPro, or:

cd ComfyUI/custom_nodes
git clone https://github.com/jetthuangai/ComfyUI-JH-PixelPro.git
cd ComfyUI-JH-PixelPro
pip install -r requirements.txt

Restart ComfyUI; it's under ComfyUI-JH-PixelPro/compositing. The pack needs ComfyUI ≥ 0.43.x, Python ≥ 3.10, plus kornia, mediapipe, opencv-python-headless, and scipy.

My honest verdict: if the pack's layer system is a mini-Photoshop, Flatten is the "Merge Visible" button - the least glamorous node in the group and the one that makes all the others useful. It's also a good debugging habit: when your composite looks wrong, flatten early and often, inspect the intermediate IMAGE, and you'll isolate whether the problem is a blend mode, an opacity, or a mask. There's no magic here, just a clean boundary between "stack you can keep editing" and "image you can actually see." For people who've been building multiply blends out of three math nodes, this boundary is the upgrade.

CategoryComfyUI-JH-PixelPro/compositing

Inputs (1)

NameTypeDefaultDescription
stackLAYER_STACK

Outputs (1)

NameTypeDescription
IMAGEIMAGE