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

Light-Tool: Add solid color background V2

Same solid backdrop, but now with margins and auto-square

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

The V2 of Light-Tool: AddBackground is the same solid-color compositor as the original, but it adds the two things you'll actually want when you're not just slapping a cutout on white: configurable margins on each side, and an auto-square mode. If you're producing thumbnail sheets, square-profile product shots, or just leaving breathing room around a subject, this is the one to reach for.

How it works

The compositing math is identical to the original - foreground weighted by alpha over a solid color, so your semi-transparent edges blend cleanly instead of going hard and jaggy. The difference is the canvas. Before compositing, V2 grows the canvas by the four margins you specify and centers your image inside it.

The square toggle is the sleight of hand worth knowing about: when on, the node compares width and height and silently adds the difference to the top/bottom or left/right margins, so the output is a perfect square with your subject centered in it. You don't have to do the arithmetic yourself, which is the whole point of the node. Say your cutout is 1024×768 - flip square on and you get a 1024×1024 canvas with the subject centered, the extra space distributed evenly.

The inputs that matter

  • image - the IMAGE tensor you're flattening.
  • color_hex (default #FFFFFF) and use_hex / R / G / B - same color machinery as V1. use_hex on means the #RRGGBB string wins; off means the three 0–255 ints.
  • square - auto-expand to a square canvas. Off by default.
  • left_margin, right_margin, top_margin, bottom_margin - extra padding in pixels on each edge, all defaulting to 0.

Output is one image tensor - fully opaque, ready for VAE encode, Save Image, or whatever's next.

When it beats the plain AddBackground

Honestly, if all you're doing is flattening a cutout onto a backdrop, V1 is simpler and you should use it. V2 earns its keep in two spots:

  1. Platform-ready output. Square Instagram posts, marketplace photos, or any slot with a strict aspect ratio - the square toggle plus a margin or two gets you there in one node instead of three.
  2. Workflows where canvas size is load-bearing. If your latent or VAE encode needs specific dimensions, having the margins be explicit inputs you can wire to an integer from another node is much nicer than hand-editing a pixel value inside a crop.

Gotchas

Same hex trap as V1 - with use_hex on, the string must be # plus exactly six hex digits or it throws a ValueError. And one thing the README doesn't shout about: V2 keeps the flattening behavior, so the output has no alpha. That's correct for compositing, but if you need the transparency preserved for a later step, this is the wrong node. Same install as the rest of the pack: ComfyUI Manager, search ComfyUI-Light-Tool, or clone and pip install -r requirements.txt from the custom_nodes directory, then restart.

CategoryComfyUI-Light-Tool/image/compositing

Inputs (11)

NameTypeDefaultDescription
imageIMAGE
color_hexSTRING#FFFFFF
use_hexBOOLEANtrue
RINT2550–255
GINT2550–255
BINT2550–255
squareBOOLEANfalse
left_marginINT0
right_marginINT0
top_marginINT0
bottom_marginINT0

Outputs (1)

NameTypeDescription
imageIMAGE