DP Add Background To PNG
Drop a solid color behind a cutout
- image
- mask
- image
- mask
You removed a background and now you've got a subject floating on transparency. This node fills that empty space with a solid color. Give it the image, give it the mask that says where the subject is, pick a color, and it composites the subject onto that background. Simple, and exactly what you need right after a background-removal step when you don't want a transparent PNG - you want the product on white, or the character on a flat color for a comp.
It's from DesertPixelAi's Desert-Pixel-Nodes, a large quality-of-life pack of utility nodes. This one is a small compositing helper, the natural next step after tools like RMBG or BiRefNet hand you a subject-plus-mask.
How it works
It takes an image and a mask. The mask marks the subject (or the background, if you flip it), and the node paints the non-subject area with the chosen color, then hands you the composited image back - plus the mask, so you can keep working with it downstream. Because it's mask-driven, the quality of the result depends entirely on the quality of the mask you feed it: a clean cutout gives a clean edge.
Note the color choices are a fixed palette of named solid colors, so this is for flat backgrounds - think catalog white, a brand color, a chroma-key style fill - not gradients or textures. For anything fancier you'd composite against another image with a different node.
The inputs and outputs that matter
image- the IMAGE, your subject.mask- the MASK that defines subject vs. background. This is the one that has to be good.background_color- a dropdown of named colors: white, black, red, green, blue, yellow, purple, cyan, orange, pink, gray, brown, and a few more. White and black cover most real use.invert_mask-falseortrue. Flip this if your mask is inside-out (subject and background swapped). It's the first thing to try when the wrong region gets filled.duplicate_layers- an integer from 1 to 5, which stacks the subject over itself. Bump it if semi-transparent edges look too faint against the new background; leave it at 1 otherwise.
Outputs are image (IMAGE - the composited result) and mask (MASK - passed along for further steps).
How to install it
- ComfyUI Manager: search "Desert Pixel", install, restart. No models needed.
- Manual:
cd ComfyUI/custom_nodes && git clone https://github.com/DesertPixelAi/ComfyUI-Desert-Pixel-Nodes,pip install -r requirements.txtif present, restart.
Under the DP category.
Common issues
By far the most common problem is the background filling the wrong side - you get the subject cut out and the background kept, or vice versa. That's a mask polarity issue: flip invert_mask. Mask conventions differ between background-removal nodes (some output the subject as white, some as black), so expect to toggle this once per pipeline and then leave it.
If the edges of your subject look haloed or fringed against the new color, that's the source mask being soft or imprecise, not this node. Tighten the mask upstream - feather it less, or use a better removal model. And if faint, semi-transparent parts of the subject wash out against the background, that's what duplicate_layers is for: raising it stacks the subject to reinforce those low-opacity areas.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| mask | MASK | — | |
| background_color | COMBO | white | 15 options: white, black, red, green, blue, yellow, +9 |
| invert_mask | COMBO | false | 2 options: false, true |
| duplicate_layers | INT | 11–5 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |