Nodes/ComfyUI-YCNodes/Image Blend MaskFit Cover
ComfyUI Node

Image Blend MaskFit Cover

Drop a foreground onto a background by telling it WHERE — a mask does the locating

By yichengup·Created 2 years ago·Updated 4 months ago· 47
Image Blend MaskFit Cover
  • background_image
  • layer_image
  • layer_mask
  • layer_alpha_mask
  • image
blend_mode
rotation0.0
opacity100
invert_maskfalse
offset_x0
offset_y0
bbox_scale1.00

Most blend nodes ask you for numbers: "place the layer at x=340, y=120, scale 1.7." That's fiddly when the target region is irregular and you'd rather say "over there." ImageBlendMaskFitCover positions by mask instead. You provide a location mask - any region drawn or detected on the background - and it computes that mask's bounding box, scales your foreground proportionally to cover it edge-to-edge (no letterboxing, no gap), and composites it with rotation, opacity, and 16 blend modes. It's the "paste this onto that specific spot" node.

How it works

The pipeline is: take layer_mask (the locator), resize it to the background, optionally invert it, and find its bounding box. That bbox is then the target. The foreground is scaled to cover the bbox while keeping its own aspect ratio, rotated if you asked, and pasted centered on the bbox. Two extra controls refine the region: bbox_scale grows or shrinks the target box (0.1–4.0), and offset_x/offset_y nudge the whole thing in pixels. Finally the locator mask is multiplied against the foreground's alpha - so the composite is shaped by the mask too, not just positioned by it - and the result is alpha-composited over the background, letting the background show through where the mask is black.

If you provide layer_alpha_mask, it's multiplied into the foreground's alpha first, which is the "use a soft/partial mask" option for getting feathered edges or holes in the layer.

The inputs that matter

  • background_image / layer_image - the backdrop and the thing you're pasting.
  • layer_mask - the locator: a MASK on the background that says where to put the layer. This is the input that makes the node special.
  • blend_mode - 16 modes including normal, multiply, screen, overlay, soft/hard light, darken/lighten, color dodge/burn, difference, exclusion, and friends.
  • rotation / opacity - rotate the pasted layer ±180°, set opacity 0–100.
  • invert_mask - flip the locator (paste everywhere except the region).
  • offset_x / offset_y / bbox_scale - refine the target box.

Output is image - a single composited IMAGE.

Where you'd reach for it

Any "put this object in this hole" job: replace a face or object with something that should fill roughly the same footprint, paste a logo into a detected region, or composite a foreground over a segment from a segmentation model. The bbox-cover behavior means you don't have to nail the scale - it fits the region, which is exactly what you want when the region came from SAM or a mask painting and "fits" is the whole requirement.

Installing it

Part of ComfyUI-YCNodes. ComfyUI Manager → search ComfyUI-YCNodes → install, or:

cd ComfyUI/custom_nodes
git clone https://github.com/yichengup/ComfyUI-YCNodes

Restart, then look under YCNode/Image. Uses PIL heavily - in the pack's standard requirements.

Gotchas

The mask does double duty (locator and alpha shaper), and that's the thing that confuses people: if your locator mask has soft edges, the pasted layer gets soft edges and its fit is based on the hard bbox of those edges. For a crisp fit, keep the locator binary; save feathering for layer_alpha_mask. Also, because it covers the bbox proportionally, a foreground with a wildly different aspect ratio than the region will be scaled to fill the box on one axis and may overflow on the other - with rotation that usually looks intentional, but check before you commit. And it re-executes on every change, so expect a re-blend each time you nudge offset_x - that's the cost of "fit by mask" versus "fit by fixed numbers."

CategoryYCNode/Image

Inputs (11)

NameTypeDefaultDescription
background_imageIMAGE
layer_imageIMAGE
layer_maskMASK
blend_modeCOMBO16 options: normal, multiply, screen, overlay, soft_light, hard_light, +10
rotationFLOAT0.0-180–180
opacityINT1000–100
invert_maskBOOLEANfalse反转定位遮罩1
offset_xINT0-4096–4096定位遮罩整体左右偏移(+为右,-为左,像素)
offset_yINT0-4096–4096定位遮罩整体上下偏移(+为下,-为上,像素)
bbox_scaleFLOAT1.000.1–4定位 bbox 额外缩放系数(>1 放大,<1 缩小)
layer_alpha_maskoptMASK

Outputs (1)

NameTypeDescription
imageIMAGE