Flatten Images By Alpha
The Photoshop 'Flatten Layers' you can actually run inside ComfyUI
- images
- flattened_image
Every ComfyUI workflow eventually hits the same wall: you've got a batch of RGBA images - masked faces, cut-out subjects, alpha'd layer passes - and you need them on one canvas. A1111 had a button for that. ComfyUI has a graph, which is great right up until you're hand-wiring a binary blend per layer. Flatten Images By Alpha (FlattenByAlpha) from the ComfyUI-AlphaFlatten pack is that missing button: feed it any batch of alpha images and it composites them top-to-bottom into a single output, Photoshop-flatten style, no per-layer nodes required.
It's a tiny node, and that's the point. The whole pack is one pure-PyTorch file - no model downloads, no pip extras beyond what ComfyUI already ships, no API, nothing to go stale. If you've ever glued masks back together with a detailer workflow (the same "detect, crop, paste back" idea Impact Pack made famous), you've done this job by hand. This just makes it one node instead of five.
How it works
The node treats your batch like layers in an editor. The first image in the batch is the bottom layer; each subsequent image blends on top using its alpha channel. It's a sequential result = result * (1 - alpha) + rgb * alpha pass in torch, so order matters - flip the batch and your composition flips with it. Batch order isn't obvious to beginners, and it's the #1 "why does this look wrong" cause with this node.
It's strict about input though: it wants a 4D [batch, H, W, 4] RGBA tensor and raises a clear ValueError if your images are missing alpha. Most samplers output RGB, so you'll usually need to convert to RGBA first (core's Convert Image node handles that) or feed it cut-outs that already carry an alpha channel.
The inputs that matter
Only one input is a real decision:
- images - your batch of RGBA images. The only thing you must wire in.
- background_color -
black,white,transparent, orcustom. Picktransparentif you're compositing further downstream; it preserves the alpha channel and outputs RGBA. Everything else flattens onto a solid color and returns plain RGB. - custom_color_r / g / b - ignored unless you picked
custom. Each is a 0–1 float (not 0–255, a common trip-up), defaulting to 0.
The output is a single flattened_image, ready to feed a VAE decode, a save node, or another composite step.
Installing it
Easiest path is ComfyUI Manager - search for "ComfyUI-AlphaFlatten" and hit install. Or, by hand:
cd ComfyUI/custom_nodes
git clone https://github.com/pixelworldai/ComfyUI-AlphaFlatten
Then restart ComfyUI. That's it - no requirements to satisfy, no weights to fetch. You'll find the node as "Flatten Images By Alpha" under image/processing.
Common gotchas
The big one is the RGBA requirement. Feeding it a normal RGB generation output errors immediately - that's the node telling you it can't composite what has no transparency, so add the alpha channel rather than fighting it.
Second: your batch has to be one rectangular tensor, so every image shares the same height and width. Differently-sized cut-outs won't batch together - pad them to a common canvas first, then flatten.
And remember the layering direction: batch item 0 is on the bottom. If your elements are vanishing under each other, reverse the order. It's a quiet little utility, but once you're compositing masked elements back onto a scene, you'll wonder how you lived without it.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| images | IMAGE | — | |
| background_color | COMBO | 4 options: black, white, transparent, custom | |
| custom_color_r | FLOAT | 0.000–1 | — |
| custom_color_g | FLOAT | 0.000–1 | — |
| custom_color_b | FLOAT | 0.000–1 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| flattened_image | IMAGE | — |