Nodes/petty-paint-comfyui-node/Petty Paint Image Composite Masked
ComfyUI Node

Petty Paint Image Composite Masked

Stamp a whole stack of masked layers onto one canvas

By mephisto83·Created 2 years ago·Updated 2 years ago· 3
Petty Paint Image Composite Masked
  • destination
  • sources
  • masks
  • IMAGE
x0
y0
resize_sourcefalse

Core ComfyUI has ImageCompositeMasked, which stamps exactly one source image onto one destination using one mask. That's fine when you're pasting a face onto a body. It's annoying when you've got a stack of layer images - a background, a character, a prop, all with their own masks - and you want them all flattened onto one canvas in a single pass. That's the gap this node fills: it runs the same masked composite, but loops over a whole batch of sources and masks for you.

This is the compositing workhorse of the petty-paint pack, the ComfyUI-side companion to Petty Paint (Andrew Porter's web canvas where you doodle and Stable Diffusion reimagines the result). In that pipeline, the app hands you a stack of RGBA layer PNGs and this node flattens them onto the scene canvas before the image gets fed back into a sampler. It's also just a genuinely handy general-purpose node if you do layer-based compositing anywhere.

How it works

For each source in your batch it runs ComfyUI's standard composite() operation: it moves channels into the (C, H, W) layout, splices the source into the destination at x, y, uses that source's own mask as the alpha, then moves channels back. The resize_source flag controls whether each source gets scaled to fit the destination before the stamp - leave it off if your layers are already canvas-sized, turn it on if you're dropping arbitrary-size plates onto a fixed canvas.

The key thing to internalize is that sources and masks are paired by index. Source 0 gets masked by mask 0, source 1 by mask 1, and so on. Get the ordering wrong and you'll silently paste the wrong cutout in the wrong place.

The inputs and outputs

  • destination - the IMAGE you're stamping onto (your canvas).
  • sources - an IMAGE batch of the things to paste in.
  • masks - a MASK batch, one per source.
  • x, y - integer pixel offsets for the stamp (0–16384).
  • resize_source - scale each source to the destination before stamping.
  • Output: one IMAGE - the destination with every source composited in.

Wire the result into a VAE encode for img2img, into PettyPaintImageSave to hand the flatten back to the app's layer folder, or just into a preview to check your cuts.

Installing it

Same install for the whole pack - ComfyUI Manager, search "petty-paint-comfyui-node", or:

cd ComfyUI/custom_nodes
git clone https://github.com/mephisto83/petty-paint-comfyui-node

Restart ComfyUI. The declared dependency is just Flask==2.1.2, and this node doesn't even use it. No models to download.

Common issues

Because this is a batch operation, the usual suspects apply: masks and sources must line up by index, and if one of your masks comes back as a bare (H, W) tensor rather than a (1, H, W) batch (a few nodes in this pack hand you Python lists), the index math goes sideways. When in doubt, preview the flattened result before you spend a generation on it. And remember x, y are absolute offsets - if you're stacking many layers, each stamp's position is whatever you set it to, not "current position plus one."

Categoryimage

Inputs (6)

NameTypeDefaultDescription
destinationIMAGE
sourcesIMAGE
masksMASK
xINT00–16384
yINT00–16384
resize_sourceBOOLEANfalse

Outputs (1)

NameTypeDescription
IMAGEIMAGE