Nodes/ComfyUI-MaxedOut/Place Image by Mask MXD
ComfyUI Node

Place Image by Mask MXD

Paste an image exactly where a mask says, no hand-aligning

By Maxed-Out-99·Created about a year ago·Updated 21 days ago· 9
Place Image by Mask MXD
  • base_image
  • mask
  • overlay_image
  • IMAGE
maintain_aspect_ratiotrue

Every time you've done the manual dance - load a base image, load an overlay, compute a bounding box, resize, paste, re-crop - you've reinvented this node. Place Image by Mask MXD reads the non-empty region of a mask, resizes your overlay to fit it, and composites it onto the base image. You pick the mask, it does the math.

It's the kind of helper that turns "composite a generated character into this scene region" from a five-node chain into one node. It's batch-aware too, so it works when your base is a sequence of frames rather than a single image - handy in video frames pipelines where you're pasting the same overlay into every frame's matching mask.

How it works

The node takes three inputs: base_image, the mask, and the overlay_image. It finds the bounding box of the mask's non-zero pixels, then pastes the overlay there. What happens next depends on the one optional toggle, maintain_aspect_ratio (on by default):

  • On - the overlay is resized to fit inside the box (like a thumbnail) and centered. No distortion, but it won't fill the box edge-to-edge if the aspect ratios differ.
  • Off - the overlay is stretched to fill the bounding box exactly. Exact fit, possible distortion.

The overlay's own alpha channel is used as the paste mask, so transparent areas of your overlay stay transparent - that matters a lot if your overlay is a cutout with soft edges rather than a hard rectangle.

The trap

If the mask is empty - all zeros, no bounding box - the node raises: "The base image must be masked where you want the overlay to appear." In a video pipeline this usually means your mask didn't come through (wrong frame, alpha channel inverted, mask dropped to a different resolution than the base). Always sanity-check the mask before wiring this in.

Output is a single IMAGE - the composited result - which feeds straight into a Save or Preview, or back into a sampler if you're doing regional regeneration.

Install

ComfyUI Manager is the easy path: search Maxed Out, install, restart. Or the manual route:

cd ComfyUI/custom_nodes
git clone https://github.com/Maxed-Out-99/ComfyUI-MaxedOut

Restart ComfyUI after. This pack is pure Python - no requirements.txt, no model downloads, nothing extra to fetch. It's one of a whole family of MXD helpers from the same pack, so you'll see the resolution matchers, comparers and WAN utilities right next to it in the node menu under MXD/.

One real-world note: since it matches masks frame-by-frame but clamps indices when batch sizes disagree, keep your mask batch the same length as your base image batch. Mismatched lengths don't crash, but you'll get the same overlay position repeated - which is usually not what you wanted.

CategoryMXD/Image

Inputs (4)

NameTypeDefaultDescription
base_imageIMAGE
maskMASK
overlay_imageIMAGE
maintain_aspect_ratiooptBOOLEANtrue

Outputs (1)

NameTypeDescription
IMAGEIMAGE