ComfyUI Node Runs on cloud

Layers Merge

Flatten a run of layers with all their settings baked in

By WASasquatch·Created 3 years ago·Updated 4 days ago· 1,844
Layers Merge
  • layers
  • layers
  • image
  • mask
  • count
first_index0
last_index-1
namemerged

Layers Merge is "merge down" for the layer stack - it flattens a run of layers into one, with every layer's opacity, blend mode, mask, placement, size, angle and mirroring baked in at composite time. The merged result takes the lowest slot of the run and is drawn normally at full opacity. Left at its defaults (first 0, last -1) it flattens the whole document in one pass. And unlike a pure "flatten to image" node, it keeps working as a stack: the merged layer stays in the document, so you can keep editing around it.

What comes out

Four outputs, and the extra three are why this node is more than a flatten:

  • layers - the document with the run replaced by the one merged layer, still numbered from 0 at the back.
  • image - the merged picture on its own, cropped to what the run covered. Wire it into Image Preview to see the flatten without rendering the whole document.
  • mask - what the merged picture leaves clear: white where nothing was drawn, black where it's solid. The description points it at Image Paste Crop or a sampler's inpaint mask.
  • count - how many layers got folded in, so a switch can tell "1" (a single layer baked) from "12".

That mask output is the quietly powerful one. Merge your subject layers, and what comes out of mask is a ready-made composite matte of everything that run drew - exactly the shape you'd hand an inpaint or a paste step. It's the pack's answer to "I built this composite by layering, now I need its silhouette as a mask."

Naming and hidden layers

The name input sets what the merged layer is called - blank calls it 'merged', or type 'plate' so Layer Select and Layer Order can match on it later. Worth doing, because after a merge the stack is smaller and index arithmetic shifts; naming the merged result keeps your downstream wiring intact.

One behaviour to internalise: a hidden layer in the run is not drawn and does not survive the merge. If you've got hidden layers you want to keep, they have to live outside the run you flatten, or you need to un-hide them first. Visible-only flattening is the sane default - it's what an image editor's "merge visible" does - but it will quietly delete things you toggled off "for now."

Installing it

Part of WAS Node Suite:

cd ComfyUI/custom_nodes
git clone https://github.com/WASasquatch/was-node-suite-comfyui.git

or ComfyUI Manager → "WAS Node Suite v3", then restart. Needs ComfyUI 0.14.0+ and Python 3.10+; v3 pulls no pip packages.

Where people trip

The biggest surprise is that a merge isn't "flatten to the canvas" - the merged image output is cropped to what the run covered, so a document with content that hangs off the run's bounds won't have that content in the image output even though it's still in the surrounding stack. And remember the run is inclusive and index-based; a hidden layer inside the range disappears. If your merge result looks like something vanished, check both - a hidden layer you forgot, or a run that didn't reach where you thought. The count output tells you how many went in, which makes both easy to spot.

CategoryWAS Suite/Image/Layers

Inputs (4)

NameTypeDefaultDescription
layersLAYERSThe stack to flatten. Wire in Add Layer, Layer Edit or anything else answering a LAYERS document.
first_indexINT0-16384–16384Lowest layer of the run, counting 0 from the back of the stack. -1 is the front layer, -2 the one under it.
last_indexINT-1-16384–16384Highest layer of the run, counted the same way. -1 = the front of the stack, so 0 and -1 together flatten everything.
nameSTRINGmergedWhat the merged layer is called. Blank calls it 'merged'. 'plate' names it plate, which Layer Select and Layer Order then match on.

Outputs (4)

NameTypeDescription
layersLAYERSThe document with the run replaced by the one merged layer, numbered from 0 at the back, for Create Layered Image or another edit.
imageIMAGEThe merged picture on its own, cropped to what the run covered. Wire it to Image Preview to see the flatten without rendering the document.
maskMASKWhat the merged picture leaves clear, white where nothing was drawn and black where it is solid. Feeds Image Paste Crop or a sampler's inpaint mask.
countINTHow many layers were folded into the one, 1 while a single layer is baked.