Nodes/ComfyUI FSL Nodes/🖼️ Composite With Mask Cropped (FSL)
ComfyUI Node

🖼️ Composite With Mask Cropped (FSL)

🖼️ Composite With Mask Cropped (FSL) — blend, then crop to the mask

By fredlef·Created about a year ago·Updated 9 months ago· 13
🖼️ Composite With Mask Cropped (FSL)
  • foreground
  • mask
  • background
  • composited_rgb
filenamecomposited_rgb.png
save_dir./outputs

The FSL pack's blender, with a twist. FSL Composite With Mask takes a foreground, a mask, and an optional background, blends them together, crops the result down to the mask's bounding box, and saves it as a file. The "Cropped" in the name is the whole personality of the node - most compositors hand back a full-canvas image; this one trims to where the action is. The README marks it [Legacy], but it's still a reasonable one-stop for product-style shots where you've cut a subject out and want it placed on a fresh background, tight.

How it works

The math is a standard alpha blend: composited = foreground * mask + background * (1 - mask), all done on numpy arrays in the node. Several sensible defaults fill in the gaps:

  • No background? It assumes a black 512×512 canvas.
  • No mask? All white - i.e., foreground wins everywhere.
  • Size mismatch? Foreground and mask are resized to match the background.

Then the "cropped" part: the mask's nonzero area is found via bounding box, and the composited image is cropped to it. That's the behavior that separates this from a generic blend node - a small subject on a big canvas comes back tight to the subject. The cropped RGB result is saved to save_dir under filename and also returned as an IMAGE tensor (composited_rgb).

Two implementation details worth knowing:

  • The mask is converted to L-mode and its bbox computed from nonzero pixels. An all-white (or all-black) mask gives an empty or full bbox - the crop is only meaningful when the mask actually marks a region.
  • The node always writes a file as a side effect. If you only want the tensor, point save_dir somewhere disposable or accept the file appearing.

The inputs

  • foreground (optional) - the image to cut out and place.
  • mask (optional) - the selection. White = keep foreground, black = show background.
  • background (optional) - what sits behind the subject. Black by default.
  • filename - output name, default composited_rgb.png (.png appended if you omit an extension).
  • save_dir - where the PNG lands, default ./outputs.

Output: composited_rgb, a single IMAGE tensor - the cropped, blended result.

Install & gotchas

Ships with the pack:

cd ComfyUI/custom_nodes
git clone https://github.com/fredlef/Comfyui_FSL_Nodes
cd Comfyui_FSL_Nodes
pip install -r requirements.txt

or ComfyUI Manager → "ComfyUI FSL Nodes", then restart. Local-only, no API key.

The gotchas are both about the mask. First, an all-white mask means the crop collapses to the full frame (and an all-black one produces an empty crop) - if your output comes back unexpectedly tight or empty, suspect the mask before the node. Second, remember it's a crop, so anything you wanted to keep outside the mask's bounding box is gone by design. If that's not what you wanted, you wanted a plain blend - which the pack's newer tooling and stock ComfyUI nodes both do without the trim.

CategoryFSL Nodes

Inputs (5)

NameTypeDefaultDescription
foregroundoptIMAGE
maskoptMASK
backgroundoptIMAGE
filenameoptSTRINGcomposited_rgb.png
save_diroptSTRING./outputs

Outputs (1)

NameTypeDescription
composited_rgbIMAGE