Nodes/ComfyUI-Light-Tool/Light-Tool: Add solid color background
ComfyUI Node

Light-Tool: Add solid color background

Sticking a solid color behind your transparent renders

By ihmily·Created 2 years ago·Updated 4 months ago· 20
Light-Tool: Add solid color background
  • image
  • image
color_hex#FFFFFF
use_hextrue
R255
G255
B255

The Light-Tool: AddBackground node is the "flatten my PNG onto a colored backdrop" node, and it's the one you reach for the second your workflow involves anything with transparency. Run a BiRefNet or InSPyReNet removal, composite a logo, generate with built-in alpha, and you'll eventually look at your output and realize the transparent regions are showing up black or checkerboard in a viewer that can't handle them. This node fixes that by baking your image onto a solid color.

It does one thing and does it cleanly: take an image with an alpha channel, composite it over a solid RGB background, and hand you back a flattened, fully opaque image. No model, no network call, no key. It's pure pixel math.

How it works

Under the hood it's a per-pixel alpha blend, exactly what you'd write by hand:

result = foreground * alpha + background * (1 - alpha)

For every pixel, the foreground color is weighted by its opacity and the background color by the inverse. Fully opaque pixels stay untouched; fully transparent ones become pure background; the semi-transparent edge pixels - the hair strands and soft shadow fringes that make or break a cutout - get a proper blended value. That's the part people underestimate: a naive "fill the alpha=0 pixels" approach gives you hard, jaggy edges, and this node doesn't do that.

It also validates your hex color. If you've got use_hex on and the string isn't a # followed by exactly six hex digits, it raises a ValueError - annoying at first, but it saves you from shipping a workflow that silently produces garbage colors.

The inputs that matter

  • image - your RGBA (or anything with transparency) IMAGE tensor.
  • color_hex - the background color as #RRGGBB, default #FFFFFF (white).
  • use_hex - on by default. Flip it off and the node reads R, G, B (each 0–255) instead, which is handy when the color comes from another node's outputs rather than a string you typed.

That's the whole set. The output is a single image tensor you can wire straight into VAE encode, a Save Image node, or the compositing stage of a photorealistic workflow - no alpha channel left to trip over.

Installation

The standard route - either ComfyUI Manager → search ComfyUI-Light-Tool → Install, or manually:

cd ComfyUI/custom_nodes
git clone https://github.com/ihmily/ComfyUI-Light-Tool.git
pip install -r requirements.txt

Then restart ComfyUI. No model files to download; the whole pack is just numpy, Pillow, and a few friends. You'll find the node under ComfyUI-Light-Tool → image → compositing.

Where people get burned

The only real failure mode is the hex validation error, and it's self-explanatory. The subtler trap: this node flattens. If you feed it a partially transparent image and wanted to keep the alpha for a later step, this is the wrong node - you want a channel split or a separate composite. If your downstream step is "stick it on a backdrop," you're in the right place. And if you need padding around the subject or an auto-square canvas, skip ahead to AddBackgroundV2, which does all of that plus the flattening.

CategoryComfyUI-Light-Tool/image/compositing

Inputs (6)

NameTypeDefaultDescription
imageIMAGE
color_hexSTRING#FFFFFF
use_hexBOOLEANtrue
RINT2550–255
GINT2550–255
BINT2550–255

Outputs (1)

NameTypeDescription
imageIMAGE