D2 Paste By Mask
Paste an object back into a scene without killing the edges
- img_base
- img_paste
- mask_opt
- image
D2 Paste By Mask is the other half of the D2 Cut By Mask story. Where its sibling carves an object out, this one puts things back - with control over where, how, and whether the edges blend. It's the node for "I regenerated this subject elsewhere, now drop it into the original scene without a visible box around it." If you've ever composited with Paint-by-number pain, this makes it a graph connection instead.
How it works
You give it a base image and a paste image, plus either a mask or a rectangle (or both), and it composites the paste image onto the base according to the paste_mode. The four modes map to the two input styles:
mask- paste the image masked bymask_opt, at position (0,0). Mask-shaped paste at the origin.rect_full- trim the paste image torect_opt's size and paste atrect_opt's position. Rectangle paste.rect_position- paste the paste image atrect_opt's position without trimming.rect_pos_mask- mask the paste image, then place it atrect_opt's position. The full-fat mode: masked shape, positioned.
The rect_opt here is the exact rect output of D2 Cut By Mask - that's the intended wiring. Cut a rectangle around a subject, regenerate it, and paste the new subject back at the original coordinates.
The inputs that matter
img_base/img_paste- the scene and the thing going in.paste_mode- one of the four above.multi_mode- how batches pair up:pair_lastandpair_onlyboth pair by index (the former reuses the last image when counts mismatch, the latter errors instead), andcrossdoes every combination. If you're pasting one image onto several bases,pair_lastis your friend.mask_opt/rect_opt- the mask and/or rectangle from the cut node.feather- blurs the paste edge by N pixels. This is the "make it not look glued on" control; a small feather hides hard seams.feather_type-simpleordistance; the distance variant feathers based on mask distance, which is usually the smoother one for irregular shapes.
One output: image, the composite.
Where it shines
The loop that makes this node earn its keep: cut a subject with D2 Cut By Mask (rectangle, round_to on), regenerate or fix that region, paste it back at the same rect with feather set, and optionally run the composite through a quick inpaint or a low-denoise pass to melt the seam. You get local edits without painting a mask by hand every time. It's also the foundation for compositing workflows where a source image and a target scene come from different places entirely - pair them up with multi_mode and paste each subject onto each backdrop.
Installing and troubleshooting
Part of D2 Nodes ComfyUI:
cd ComfyUI/custom_nodes
git clone https://github.com/da2el-ai/D2-nodes-ComfyUI
or search "D2 Nodes ComfyUI" in ComfyUI Manager. No extra dependencies, no model downloads.
The classic mistakes: forgetting the rect wire (rect modes fall back to pasting at (0,0) at full size), and paste/base images of mismatched sizes producing odd results - the node checks dimensions and errors on incompatible combinations rather than guessing, which is honestly the better failure mode. And if the pasted edge looks like a sticker, that's not a bug: raise feather a few pixels, or finish with a low-denoise pass over the seam.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| img_base | IMAGE | — | |
| img_paste | IMAGE | — | |
| paste_mode | COMBO | 4 options: mask, rect_full, rect_position, rect_pos_mask | |
| multi_mode | COMBO | 3 options: pair_last, pair_only, cross | |
| mask_optopt | MASK | — | |
| rect_optopt | INT | — | |
| featheropt | INT | 00–100 | — |
| feather_typeopt | COMBO | simple | 2 options: simple, distance |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |