Nodes/Masquerade Nodes/Paste By Mask
ComfyUI Node Runs on cloud

Paste By Mask

Composite a cutout back where it belongs

By BadCafeCode·Created 3 years ago·Updated 2 years ago· 479
Paste By Mask
  • image_base
  • image_to_paste
  • mask
  • mask_mapping_optional
  • IMAGE
resize_behavior

Paste By Mask is the "stitch" half of the crop-inpaint-paste pattern Masquerade Nodes was built around: you cut a region out with Cut By Mask, work on it (inpaint it, upscale it, recolor it, whatever), and Paste By Mask puts it back into the original image at the right spot. It's the node that makes high-resolution masked edits actually usable instead of leaving you with a disconnected patch.

The interesting part is resize_behavior, because the piece you're pasting back rarely matches the exact pixel dimensions of the area you're pasting into - you might have upscaled it, or generated it at a different resolution than the crop. resize stretches it to fit exactly, ignoring aspect ratio. keep_ratio_fill preserves aspect ratio but lets the resized image overflow the masked area's edges rather than distort it. keep_ratio_fit also preserves aspect ratio but keeps the whole thing contained inside the masked area, which can leave gaps if the ratios don't match. source_size and source_size_unmasked both use the pasted image's own size instead of resizing it at all, centering it on the mask - the "unmasked" variant lets it spill outside the mask's boundary if it's bigger, while plain source_size clips it to stay inside.

The inputs that matter

  • image_base - the original image you're pasting into.
  • image_to_paste - the edited/cropped piece to composite back.
  • mask - where, in image_base, the paste should land.
  • resize_behavior - one of the five modes above.
  • mask_mapping_optional - wire this from Separate Mask Components' output when you're working with a batch of masks that came from splitting one image into multiple regions; it makes sure each piece pastes back into the correct source image rather than getting mismatched.

The output is the composited image - the base image with the pasted content blended in wherever the mask said to.

One tip from the pack's own docs worth keeping: if you want to paste only part of what you cut (say, blend the edges rather than pasting a hard rectangle), add alpha to image_to_paste before this node - Combine Masks with multiply_alpha is the way to do that - rather than trying to reshape the mask itself. Changing the paste mask independently of the mask you cut with tends to shift where and how large the paste lands, which is exactly the kind of subtle misalignment this node is prone to.

Installing it

Paste By Mask is part of Masquerade Nodes. ComfyUI Manager - search "Masquerade Nodes" - or manually cd ComfyUI/custom_nodes && git clone https://github.com/BadCafeCode/masquerade-nodes-comfyui, then restart. No models or extra pip packages needed for this specific node.

Common issues

This is the node in the pack that generates the most confused questions in the wild, and the pattern is consistent: a faint square outline or a visible tone shift around the pasted region, especially after inpainting on certain checkpoints, or the paste landing off-center from where it should be. Both are usually traceable to the same root cause - what's feeding into Change Channel Count upstream of the paste, and whether the mask used to cut and the mask used to paste actually match. Users have reported that switching Change Channel Count between mask, RGB, and RGBA changes both the visibility of a seam and the paste's alignment, in ways that aren't obvious from the node names alone; if you hit this, try each channel mode and compare, and consider an ImageCompositeMasked-style blend (or Mix Images By Mask) as a fallback if you can't get a clean result. It's also worth double-checking, if a node in your saved workflow shows as "undefined" after an update, that your Masquerade Nodes install is current - stale node-mapping caches after a partial update are a known way for a specific node in this pack to stop resolving even though the rest of the graph loads fine.

CategoryMasquerade Nodes

Inputs (5)

NameTypeDefaultDescription
image_baseIMAGE
image_to_pasteIMAGE
maskIMAGE
resize_behaviorCOMBO5 options: resize, keep_ratio_fill, keep_ratio_fit, source_size, source_size_unmasked
mask_mapping_optionaloptMASK_MAPPING

Outputs (1)

NameTypeDescription
IMAGEIMAGE