ComfyUI Node

CNP Paste

Put your refined crop back without the seam nightmare

By dapa5900·Created 2 months ago·Updated 2 months ago· 0
CNP Paste
  • cropped_image
  • pipe
  • IMAGE

Pasting an inpainted crop back onto the original is where seams live. ComfyUI's built-in ImageCompositeMasked works, but it makes you wire up the original, the crop, the mask, and the coordinates yourself, and get one of them slightly wrong and you get a floating rectangle. CNP Paste is the second half of this two-node pack, and its whole trick is that it doesn't make you wire any of that: feed it the refined crop plus the pipe from CNP Crop, and it composites everything back at the exact original spot with mask-based alpha blending.

It's the "paste" in crop-and-paste. The loop is: CNP Crop cuts the masked region out at a resolution your model can actually render, you run any model on that crop (inpaint, detail, upscale, whatever), then CNP Paste stitches it back onto the original canvas. Unmasked pixels are copied from the original untouched - the bit-identical guarantee that made crop-and-stitch the community's default inpainting pattern in the first place, so your VAE round-trip can't degrade the rest of the frame.

How it works

CNP Paste reads a pipe object with three things CNP Crop stashed in it: the crop's coordinates and sizes, the mask, and the original image. That last part is the ergonomic win - you don't even re-supply the original; it's carried along for the ride. The node then:

  1. Resizes your refined crop back to the padded bbox size (LANCZOS, so it matches what CNP Crop produced).
  2. Resizes the mask to match.
  3. Alpha-blends at the stored (x, y) offset: crop × mask + original × (1 − mask).

That's it. The alpha blend means only the masked region is replaced - the crop fades in through the mask, and everything outside it stays exactly as it was.

The two inputs and the contract

Only two inputs: cropped_image (IMAGE) and pipe (PIPE). Output is a single IMAGE - the full composite, ready for a Save node. It's about as close to "nothing to configure" as a ComfyUI node gets.

But that pipe is a contract, and it's the one thing to keep in mind. It's not a generic pipe - it's a dict with this pack's specific keys, so a pipe from another node suite won't work, and if you feed a crop that came from a different image or a different batch than the pipe, the coordinates won't line up and you'll get garbage pasted in the wrong spot. As long as you keep the crop and its pipe together (same batch order), you're fine. That's also the lock-in cost the KB flags about pipe-style nodes generally: adopt this pack's bus and you're married to it.

Install

ComfyUI Manager → Install Custom Nodes → search "CNP Crop And Paste", or:

cd ComfyUI/custom_nodes
git clone https://github.com/dapa5900/ComfyUI-CNP-CropAndPaste.git

Restart and it's under Crop And Paste. Dependencies are just torch, numpy, and Pillow - all already present, nothing to download.

The honest caveats

There's no mask-blur option. The blend is a hard alpha over the masked region, so if you see a visible rectangle edge, the fix is upstream: give the crop more padding in CNP Crop (32–64px), or deal with color drift from the inpaint pass by lowering its denoise. If you want blur control, mask post-processing, and a more battle-tested implementation of this whole pattern, ImageCompositeMasked (core) or lquesada's Inpaint CropAndStitch is what most people end up on. CNP Paste is the lightweight option for when you want the loop with the least wiring - and that's a perfectly good reason to reach for it.

CategoryCrop And Paste

Inputs (2)

NameTypeDefaultDescription
cropped_imageIMAGE
pipePIPE

Outputs (1)

NameTypeDescription
IMAGEIMAGE