FL Paste By Mask
Composite one image onto another wherever a mask says to
- image_base
- image_to_paste
- mask
- mask_mapping_optional
- IMAGE
The generic "put image B onto image A, only where the mask is white" job - a piece that shows up constantly in inpaint-and-composite workflows, region-swap tools, and anything that generates a piece separately then needs it stitched back in. FL_PasteByMask handles the resizing, blending, and feathering that job actually needs, instead of you gluing together a resize node, a mask-multiply, and an alpha composite by hand every time.
How it works
You give it a base image, an image to paste, and a mask locating where the paste should land. The interesting part is resize_behavior, because "how should the pasted image fit the masked area" has more than one reasonable answer depending on what you're doing: resize stretches the paste to exactly fill the mask's bounding box (can distort aspect ratio), keep_ratio_fill scales to cover the area while preserving aspect ratio (may crop overflow), keep_ratio_fit scales to fit inside while preserving aspect ratio (may leave gaps), source_size pastes at the paste-image's native size regardless of mask dimensions, and source_size_unmasked does the same but ignores the mask shape for sizing purposes. Picking the wrong one is the single most common way this node produces a result that looks "almost right but stretched." Once sized, blend_mode (normal through difference - nine total) controls how the paste combines with what's underneath, and feather_amount softens the mask edge so the seam isn't a hard cutout line.
The inputs and outputs that matter
image_base,image_to_paste,mask- the three required pieces. Note the mask here is typedIMAGE, not ComfyUI's nativeMASKtype - if you're feeding it from a standard mask output, you may need a conversion step first.resize_behavior- the decision that most affects how correct the final composite looks; pick based on whether preserving the paste's aspect ratio matters more than exactly filling the masked region.blend_modeandfeather_amount(0–100) - how the edges and colors blend. Start withnormaland a small feather (a handful of pixels) unless you have a specific compositing reason for something else.mask_mapping_optional(MASK_MAPPING) - for batch workflows where your base images and paste images aren't a clean 1:1 pairing, this lets you specify which mask/paste goes with which base index instead of assuming positional order.- Output:
IMAGE- the composited result.
How to install it
Via ComfyUI Manager: search "ComfyUI_Fill-Nodes" and install, or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/filliptm/ComfyUI_Fill-Nodes
then restart ComfyUI. Standard image-compositing math, no extra dependency for this node. The pack overall is a large, general-purpose collection from filliptm, one prolific solo author, also covering PDF tools, GPT/Gemini/Fal API wrappers, and a full KSampler family; this node's needs are modest by comparison.
Common issues & troubleshooting
Pasted content looks stretched or squashed. Almost always resize_behavior set to resize on a paste image whose aspect ratio doesn't match the mask's bounding box. Switch to keep_ratio_fill or keep_ratio_fit depending on whether you'd rather crop overflow or leave a gap.
Hard, visible seam around the pasted content. Bump feather_amount up - even a small amount of edge softening does most of the work of hiding a composite seam, and it's a common thing to forget to set since it defaults to 0.
Wrong image lands on the wrong base in a batch. If you're running batches of unequal size or non-1:1 pairings, check mask_mapping_optional - without it the node assumes positional (index-matched) pairing, which silently produces wrong results if your batches aren't actually aligned that way.
Mask input rejected. Remember this node wants IMAGE-typed mask data, not ComfyUI's native MASK type - a direct wire from a mask-generating node may need a mask-to-image conversion step first.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| image_base | IMAGE | — | |
| image_to_paste | IMAGE | — | |
| mask | IMAGE | — | |
| resize_behavior | COMBO | 5 options: resize, keep_ratio_fill, keep_ratio_fit, source_size, source_size_unmasked | |
| blend_mode | COMBO | normal | 9 options: normal, multiply, screen, overlay, soft_light, hard_light, +3 |
| feather_amount | INT | 00–100 | — |
| mask_mapping_optionalopt | MASK_MAPPING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |