Nodes/D2 Nodes ComfyUI/D2 Paste By Mask
ComfyUI Node

D2 Paste By Mask

Paste an object back into a scene without killing the edges

By da2el-ai·Created 2 years ago·Updated 5 days ago· 66
D2 Paste By Mask
  • img_base
  • img_paste
  • mask_opt
  • image
paste_mode
multi_mode
rect_opt
feather0
feather_typesimple

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 by mask_opt, at position (0,0). Mask-shaped paste at the origin.
  • rect_full - trim the paste image to rect_opt's size and paste at rect_opt's position. Rectangle paste.
  • rect_position - paste the paste image at rect_opt's position without trimming.
  • rect_pos_mask - mask the paste image, then place it at rect_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_last and pair_only both pair by index (the former reuses the last image when counts mismatch, the latter errors instead), and cross does every combination. If you're pasting one image onto several bases, pair_last is 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 - simple or distance; 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.

CategoryD2/Image

Inputs (8)

NameTypeDefaultDescription
img_baseIMAGE
img_pasteIMAGE
paste_modeCOMBO4 options: mask, rect_full, rect_position, rect_pos_mask
multi_modeCOMBO3 options: pair_last, pair_only, cross
mask_optoptMASK
rect_optoptINT
featheroptINT00–100
feather_typeoptCOMBOsimple2 options: simple, distance

Outputs (1)

NameTypeDescription
imageIMAGE