Layer Replace Image
The way back into a stack
- layers
- image
- mask
- layers
- index
This is the node that makes a layer stack a pipeline instead of a dead end. Layer Replace Image swaps one layer's picture for another while leaving its placement, angle, opacity, blend mode and name alone. Why does that matter? Because the whole compositor is one-way: Add Layer only appends new layers, and Create Layered Image only flattens. If you want to run one element of your composite through a filter - a blur, a grade, an upscale, a relight - the stack won't let you. You have to take the layer out, process it, and put the result back exactly where it lived.
The round trip
Here's the pattern the node description itself recommends:
- Take the stack apart with Layers to Image Batch - you get each layer as a frame, its mask, where it sits as bounds, and its name.
- Run the frames through any image filter in the pack. Because the placement comes out alongside, nothing needs to be tracked by hand.
- Wire the processed batch into Layer Replace Image's
imageinput, and the layer lands back in the stack at the same spot, still named, still masked.
This is the compositing version of the detect-crop-fix-paste loop the detailing world knows from Impact Pack - same idea, but working on layers you built yourself instead of detected regions. Feed it a batch and the layer draws one picture per frame, the same way Add Layer carries batches.
The inputs that matter
image- the new picture. A batch is carried whole.index/layer_name- which layer is replaced (0 from the bottom, -1 front, name wins when set).size-keep the drawn sizeholds the box the layer already filled, so a filter that changed resolution still lands in the same place;take the new picture's sizegrows or shrinks the layer to its own pixels.mask(optional) - what the layer covers. Left unwired, the layer keeps the mask it had; wire a fully white mask to clear one.name(optional) - rename it while you're at it. Blank keeps the current name so later Layer Edit / Layer Select calls still find it.
Outputs are the updated layers and an index telling you which layer you touched, in case a downstream node needs to know.
Installing it
Part of WAS Node Suite. Manager → "WAS Node Suite v3", or:
cd ComfyUI/custom_nodes
git clone https://github.com/WASasquatch/was-node-suite-comfyui.git
Restart. Requires ComfyUI 0.14.0+ and Python 3.10+. v3 installs no pip packages.
Where people trip
The classic error is treating this like Add Layer - feeding it an image and expecting a new layer. It isn't. It edits in place; a brand-new stack with one layer gets an empty error asking for a layer to replace. The second gotcha is replacing a layer that had a mask with a new image and no mask wired - the old mask stays, so a transparent-backed PNG can come back cropped by coverage you forgot it had. Wire a white mask if the new picture should own its shape. And when the round-trip filter changes the resolution, keep size on keep the drawn size unless you actually want the layer's footprint to change - otherwise that carefully aligned composite quietly shifts.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| layers | LAYERS | The stack holding the layer to change. Wire in Add Layer, Layer Edit or anything else answering a LAYERS document. | |
| image | IMAGE | The picture that goes in. A batch is carried whole, so the layer draws one picture per frame the way Add Layer does. | |
| index | INT | -1-16384–16384 | Which layer is replaced, counting 0 from the back of the stack. -1 is the front layer. Ignored while layer_name names one. |
| layer_name | STRING | Name of the layer to replace instead of index. Blank uses index. 'sky' finds a layer called Sky, and finds Sky Backdrop where nothing is called exactly Sky. | |
| size | COMBO | What the layer is drawn at afterwards. `keep the drawn size` holds the box it already filled, so a filter that changed the resolution still lands in the same place; `take the new picture's size` draws it at its own pixels, growing or shrinking the layer. | |
| maskopt | MASK | What the layer covers, white where it paints, as every mask in this pack reads. Left unwired the layer keeps the mask it already had; wire a fully white mask to clear one. | |
| nameopt | STRING | What the layer is called afterwards. Blank keeps the name it has, so a later Layer Edit or Layer Select still finds it; 'sky graded' renames it. |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| layers | LAYERS | The stack with the new picture in it, for Create Layered Image or another edit. |
| index | INT | Which layer was replaced, counting 0 from the back. |