BlendByMask
Paste one image onto another and let the mask do the negotiating
- background_image
- background_mask
- blend_image
- blend_mask
- IMAGE
- MASK
BlendByMask is the ComfyPanel compositing workhorse: take a blend_image, stick it onto a background_image, and use masks to decide both where it goes and how hard it lands. It's the node you reach for when a simple paste isn't enough - when the background has a region you want to fill, the blend image needs scaling to fit, and the seam has to be softened before anyone's eye catches it.
The mechanism is classic masked compositing, with a generous serving of auto-fit options. The node finds the background's mask region (it thresholds the mask and pulls contours), then scales the blend image so it covers that region. maximize_fill chooses whether the blend is scaled to cover the mask (like CSS object-fit: cover, clipping the overflow) or to fit inside it. align_by_mask centers the blend on the mask's bounding box instead of the canvas center - exactly what you want when the background mask is off-center. Then clip_by_mask gates the blend's alpha with the background mask itself, so the paste respects the shape of the region rather than painting over it. crop_by_mask optionally crops the blend image down to its own mask first.
The alpha math is worth understanding because it's where the blend gets its name: blend_alpha = blend_mask × blend_strength, and if clip_by_mask is on, that gets multiplied by the background mask value. blend_strength (0–1, default 1) is your opacity dial; mask_blur (0–50) Gaussian-blurs the background mask before compositing, which is the difference between a hard-edged stamp and a feathered, paintable-looking transition. The optional blend_mask input swaps in a custom mask for the blend image when you don't want to use its alpha channel (or the whole image). If the blend image has an alpha channel, it's used automatically.
The two outputs, IMAGE and MASK, are the finished composite and the actual region where blending happened (alpha above a tiny epsilon, thresholded to 0/255) - that output mask is handy if you want to feed the composited area into a further pass or an inpainting step.
Where you'd actually use this: pasting a generated texture or a relit object into a scene, putting a newly generated subject onto a background while keeping the mask region under control, or assembling layers in a ComfyPanel Photoshop workflow where the panel expects a clean image + mask back. It's one of the few nodes in this pack where the README's "built by designers for designers" line actually shows - the auto-fit and alignment options are the kind of thing a PS user expects from a smart object, not a script.
Installing it
cd ComfyUI/custom_nodes
git clone https://github.com/Ginolazy/ComfyPanel
# restart ComfyUI
or ComfyUI Manager → "ComfyPanel". The pack pulls in kornia, opencv-python, and scipy on top of the usual torch/numpy/Pillow stack - all standard, no model files. If the pack fails to import, the most likely culprit is a missing kornia, since ComfyUI's core env doesn't ship it by default.
One trap to flag: if both masks are fully uniform (say, an all-white background mask), the contour step finds a single giant region and align_by_mask centers on the whole canvas - which is probably what you want anyway. The node silently returns the inputs unchanged if it can't find any contours at all, so an empty mask won't crash you; it'll just make the node look like it did nothing. If a blend "doesn't take," check your background mask first.
Inputs (11)
| Name | Type | Default | Description |
|---|---|---|---|
| background_image | IMAGE | — | |
| background_mask | MASK | — | |
| blend_image | IMAGE | — | |
| blend_strength | FLOAT | 1.000–1 | — |
| mask_blur | FLOAT | 0.00–50 | — |
| maximize_fill | BOOLEAN | true | — |
| clip_by_mask | BOOLEAN | true | — |
| crop_by_mask | BOOLEAN | false | — |
| scale_by_mask | BOOLEAN | true | — |
| align_by_mask | BOOLEAN | false | — |
| blend_maskopt | MASK | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |
| MASK | MASK | — |