PDtools:Add Background
Add Background — the 'give my transparent PNG a solid backdrop' node
- image
- mask
- image
Transparent PNGs are great until you actually want to look at them, or save them somewhere that hates alpha. PDtools:Add Background (ImageAddBackground) is the node that takes a transparent image - or an image plus a mask - and composites it onto a solid color background. Output is the exact same size as the input: no canvas resize, no letterboxing, just the pixels set down on a flat backdrop.
Why you'd want it
This is the natural second half of the background-removal pipeline. Cut a subject out with BiRefNet, rembg, or whatever you're using, and you get a transparent layer that's awkward to preview, awkward to JPEG, and useless on anything that flattens alpha to black. This node is the "put it back on something" step. It's also handy for mockups - drop a cutout onto a colored card before compositing it into a scene, or give a transparent render a clean white base before a save node that doesn't handle alpha.
How it works
The implementation is simple and it shows. The node parses color with PIL's ImageColor.getrgb, so you can pass either a HEX string like #FFFFFF or an English color name like red or black. It creates a solid background canvas at the input's exact dimensions, then decides what's "subject" using the image's alpha channel or an optional mask. The key control is invert_mask, which defaults to True - ComfyUI masks are conventionally "white = keep", so the inversion is what maps "transparent = background" correctly. If the color string is invalid, it quietly falls back to white rather than erroring out, which is friendly but worth knowing about when debugging.
The inputs that matter
image- what you're compositing. If it's a genuinely transparent PNG, its own alpha is used.color- the background. HEX or name, default#FFFFFF.invert_mask- flip which side counts as the subject. The defaultTrueis right for normal ComfyUI masks; if your mask arrives inverted, flip this.mask(optional) - lets you drive the composite with a mask instead of relying on the image's alpha, which you need when the input is an RGB image with no alpha channel.
Output is a single IMAGE at the same resolution as the input, ready for Save Image or further compositing.
Installing
Part of the 7BEII/Comfyui_PDuse pack. Through ComfyUI Manager, search "Comfyui_PDuse" and install, or:
cd ComfyUI/custom_nodes
git clone https://github.com/7BEII/Comfyui_PDuse
cd Comfyui_PDuse
pip install -r requirements.txt
Restart after install. No model downloads; the pack's dependencies are the usual Pillow/numpy/opencv set, with torch coming from ComfyUI.
Where people get burned
The classic mistake is feeding in an RGB image with no alpha and no mask - you get the original image sitting on the color, which looks like nothing happened. If your "transparent" PNG actually has a flattened checkerboard or an opaque background, no node can guess what's transparent; clean that up upstream first. And remember the invert: if you wired in a mask and the subject comes out as a hole, the default invert_mask=True is doing its job - flip it.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| color | STRING | #FFFFFF | — |
| invert_mask | BOOLEAN | true | — |
| maskopt | MASK | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |