trLayering
Stack images on a background — white cutouts get handled for you
- base_image
- add_layer1
- add_layer2
- add_layer3
- IMAGE
Half the images you generate come out on a white background. If you've ever wanted to drop a generated render onto a real background - or stack a couple of elements onto one canvas - without leaving ComfyUI for a paint program, trLayering is the quick-and-dirty answer. It takes a base image, up to three layers on top, automatically knocks the white out of each layer, and composites everything together. One node, one output, done.
The readme sums up the intent neatly: it "will remove white background and use it as transparent layers." It's not a masking powerhouse, and it knows it - there's a TODO: add alpha control sitting in the source, which tells you the author shipped the version that was good enough. For clean, flat, white-background cutouts it genuinely is good enough.
How it works
The white-removal is a per-pixel test, not a clever ML keying. For each layer:
- Every pixel where red, green and blue are all above a brightness threshold (80) and within 10 of each other - i.e. near-white - has its alpha set to 0.
- The layer is resized to match the base image.
- It's alpha-composited onto whatever is underneath, in the order you connected it.
So layer 1 sits on the base, layer 2 sits on layer 1, layer 3 on top of that. The thresholds are hardcoded in the node; there's no slider to loosen or tighten the cut, and no per-layer opacity. The one thing you control is the order.
The inputs that matter
- base_image (required) - the bottom layer, what everything else lands on.
- add_layer1 (required) - the first layer on top. At least one is mandatory.
- add_layer2 / add_layer3 (optional) - the second and third layers. Leave them disconnected if you only need one.
The single output is an IMAGE tensor, ready for SaveImage or further processing.
Installing it
trNodes is a tiny repo with no model downloads - the only "weight" is Python dependencies:
cd ComfyUI/custom_nodes
git clone https://github.com/trojblue/trNodes
Then, with ComfyUI's own python (the README spells it python_embeded/python.exe for the portable build):
python_embeded/python.exe -m pip install opencv-python scikit-image blendmodes
ComfyUI Manager works too (search "trNodes") - just remember there's no requirements.txt, so Manager clones the repo but won't install those deps for you. Restart ComfyUI and the node appears under trNodes.
Gotchas
Two things will actually bite you, plus one that's more noise than trouble:
- Pillow 10 kills it as shipped. The resize call uses
Image.ANTIALIAS, a constant that Pillow removed in version 10 - and modern ComfyUI ships Pillow 10 or later. So the node can die withAttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS'the first time it runs. The fix is a one-line patch: changeImage.ANTIALIAStoImage.Resampling.LANCZOS. - It only cuts near-white. Off-white backgrounds, shadows, or white pixels inside the artwork all get knocked out too. Feed it a layer with soft edges or a gradient and you'll get halos. For anything that isn't a clean white cutout, the README itself points at WAS Node Suite's "Image Blend by Mask" as the better tool.
- A phantom pip install. On first run the code tries to
import blend_modesand, if missing, auto-runspip install blend-modes- but the actual compositing is plain Pillowalpha_composite, so that package is never even used. If you see a stray install happen (or fail) at startup, it's harmless; ignore it.
Honest take: this is a "good enough, shipped" utility. For white-background renders it saves you a trip to an external editor. For anything softer, grab WAS. And if it errors on first use, it's the Pillow patch above, not you.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| base_image | IMAGE | — | |
| add_layer1 | IMAGE | — | |
| add_layer2opt | IMAGE | — | |
| add_layer3opt | IMAGE | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |