ImageCompositeMasked (AnotherUtils Memory Safe)
ImageCompositeMasked without the OOM — the memory-safe paste node
- destination
- source
- mask
- IMAGE
Compositing one image onto another sounds trivial until you do it to a big batch of full-resolution images at once, and your VRAM - or worse, your CPU allocator - throws the kind of DefaultCPUAllocator: not enough memory error that ends a session. That's the exact scenario this node exists for. It's a re-implementation of ComfyUI's native ImageCompositeMasked, but it processes each image in the batch one element at a time instead of smashing the whole stack through at once.
The display name says it: "ImageCompositeMasked (AnotherUtils Memory Safe)". The memory-safe part isn't marketing. When you're compositing hundreds of faces back onto a batch of crops, or pasting detail-region outputs into a full-res canvas across a whole animation, doing it element-wise keeps the peak allocation flat instead of multiplying by batch size. Same result, far fewer OOMs.
How it works
The mechanism is straightforward: for each item in the destination/source batch, it pastes the source image onto the destination at position (x, y), applies the optional mask to control the alpha of the pasted region, and - importantly - loops through the batch rather than vectorizing everything in one giant tensor operation. The code comment literally quotes the OOM error it's dodging.
It also calls an alpha-fix helper on both inputs first, so RGBA sources behave predictably when they hit the paste. That's the kind of detail that usually costs you an afternoon of debugging elsewhere.
The inputs that matter
destination(IMAGE) - the base image you're pasting onto.source(IMAGE) - what gets pasted on top.x/y(INT) - where the top-left corner of the source lands on the destination. Range goes to 8192, so oversized placements are tolerated (clipped, presumably) rather than crashing.resize_source(BOOLEAN) - resize the source to match the destination before pasting. Off by default.mask(MASK, optional) - controls where the source shows through. This is the input that turns a plain paste into a "merge these two regions" operation. Skip it and you get a hard rectangular paste.
Output is a single IMAGE, ready to feed a VAE encode, a preview, or the next compositing stage.
Installing it
It's part of the AnotherUtils pack:
cd ComfyUI/custom_nodes
git clone https://github.com/marcoc2/ComfyUI-AnotherUtils.git
Restart ComfyUI after the clone. Or use ComfyUI Manager and search "AnotherUtils". No extra Python dependencies to chase - the pack deliberately ships without a requirements.txt, which is refreshing given how many packs make you resolve one conflict to install another.
Where people get burned
The main thing to know: if your batches are small and your images modest, this node is slower than the native one - the loop costs a little throughput. It's a trade, not a free lunch. Reach for it when you're compositing a large batch of big images and the native node keeps blowing up, and don't bother otherwise. Also worth noting the output isn't a list - a batch in, a batch out - so don't expect to get your elements back separately unless you're running small batches.
For the classic FaceDetailer-style loop - detect regions, paste improved versions back - this is a genuinely useful drop-in replacement that keeps your long batch runs alive.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| destination | IMAGE | — | |
| source | IMAGE | — | |
| x | INT | 00–8192 | — |
| y | INT | 00–8192 | — |
| resize_source | BOOLEAN | false | — |
| maskopt | MASK | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |