Image Blend by Mask (Legacy)
The compositing node done right — pure PyTorch, auto-resize, no hunting through other packs
- destination
- source
- mask
- blended_image
Blending two images with a mask is the most common compositing operation in ComfyUI, and it's usually more fiddly than it should be. Image Blend by Mask is the pack's take on the classic: two images, one mask, one blend_amount, and out comes the composite. The reason to use this over whatever pile of nodes you were building by hand is that it handles the boring-but-fatal details for you - mismatched resolutions, mismatched batch sizes, device placement - and it does the math in pure PyTorch so it's fast.
How it works
The blend is source × (1 − blend_mask) + target × blend_mask. Where the mask is white, the target image shows through; black keeps the source. The blend_amount slider (0–1) scales the mask's strength, so 1.0 is a full mask-driven blend and 0.5 is a half-strength one. Flip invert_mask and the roles swap - the source shows through the white areas instead.
The quality-of-life parts are where this node earns its keep:
- If
target_imageormaskis a different size thansource_image, it resizes them to match automatically. No manual "resize image to same dims" node in your graph. - Batch sizes get cycled, so a batch of 8 sources can blend against a single target without errors.
- Everything is moved onto the source's device, so no CPU/GPU mismatch crashes.
The inputs
- source_image / target_image - the two images. Remember which is which: target is the one that wins in the white mask areas.
- mask - controls where and how much.
- invert_mask - flips the mask polarity.
- blend_amount - global strength of the effect, 0–1.
Output: IMAGE.
Where you'd use it
It's the natural endpoint of the pack's crop-uncrop pipeline (paste processed crops back with a mask-based feather), and it's great for the classic realism move of compositing a generated foreground onto a photographic background - the KB's photorealism work is full of "generate separately, composite by mask" workflows. Blend amount at 1.0 with a soft mask is the standard, but dropping it to 0.6–0.8 is a fast way to force a more natural integration when the composite looks too clean.
Installing it
Part of Pirog's Nodes:
cd ComfyUI/custom_nodes
git clone https://github.com/Pirog17000/Pirogs-Nodes
pip install -r Pirogs-Nodes/requirements.txt
Or search "Pirog's Nodes" in ComfyUI Manager and restart. No extra dependencies - this one is torch-only by design.
Gotchas
The one thing that trips people up is direction: with invert_mask off, the target is what appears in the mask's white areas. If your composite comes out backwards, that's usually it - flip invert_mask or swap the images. And while auto-resize is convenient, it stretches the smaller image to fit rather than centering it, so mismatched aspect ratios still look wrong even though they don't error. Size your images properly upstream if the result matters.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| destination | IMAGE | Base image retained where the mask or blend strength is zero. | |
| source | IMAGE | Image combined with the destination using the selected blend mode. | |
| mode | COMBO | add | Color blend operation applied between the source and destination images. |
| blend_percentage | FLOAT | 1.000–1 | Overall blend strength multiplied by the optional mask. |
| resize_source | BOOLEAN | false | Resizes the source to destination dimensions with bicubic interpolation; otherwise dimensions must match. |
| mask | MASK | Controls where the blend is applied; it is resized and singleton batches broadcast to the image batch. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| blended_image | IMAGE | — |