create_Mask_match_shape2
The current version of Apt_Preset's mask-fit compositor
- bimg
- bmask
- fimg
- fmask
- composed_image
- new_background
- foreground_layer
- foreground_mask
This is the actively-maintained successor to create_Mask_match_shape - same core job, composite a masked foreground onto a masked background while fitting it to the target region, but with clearer, documented semantics for exactly how the fitting works. If you're starting fresh and both nodes show up in your search, this is the one to use.
What it is and why you'd reach for it
Compositing a foreground onto a background where you don't want to eyeball the scale and position by hand is a common enough need - sticker-style cutout placement, swapping an object into a scene at the right size, building composite reference images. This node handles the "does the foreground actually fit the target region" problem for you, with two clearly-defined auto-fit modes instead of guesswork.
How it works - straight from the node's own docstring
Unusually, this node ships its own explanation in its description field, which is about as authoritative as it gets:
scale_mode- options areNone,width_align,height_align,auto-in,auto-out.Nonedisables auto-scaling.auto-inmeans the foreground's valid (unmasked) area ends up fully contained within the background's valid area.auto-outmeans the background's valid area ends up fully contained within the foreground's valid area.align_modeis a 9-position grid alignment choice.
That's a real, meaningful distinction: auto-in shrinks the foreground to fit inside the target region (nothing spills over the edges), auto-out grows it to cover the region completely (the foreground may extend past it). Pick based on whether you want the foreground fully contained or the background fully covered.
One thing the schema doesn't fully spell out: there are two separate color pickers here, b_color (7 options, including using bimg itself as the fill) and bjimg_color (6 options) - both clearly background-fill related, but the exact division of labor between them isn't documented. The fastest way to learn it is to toggle one, leave the other fixed, and watch how new_background changes.
Inputs and outputs that matter
bimg/bmask(required) - background image and mask.scale_mode(optional, defaultauto-in) - the fit behavior described above.align_mode(optional, defaultcenter, 9 positions) - where the foreground sits within the target region: corners, edge-centers, or dead center.f_smoothness/f_opacity- edge feathering and blend strength on the foreground.fimg/fmask(optional) - the foreground;f_x_offset/f_y_offset,f_scale,f_rotfor manual fine-tuning on top of the auto-fit.
Outputs: composed_image, new_background, foreground_layer, foreground_mask - the full composite plus its individual layers.
Installing it
Through ComfyUI Manager: search ComfyUI-Apt_Preset, install, restart. Manually:
cd ComfyUI/custom_nodes
git clone https://github.com/cardenluo/ComfyUI-Apt_Preset.git
Run install.bat on Windows for dependencies; on Linux/Mac install the requirements yourself. No models needed - pure compositing math.
Common issues
If your foreground looks clipped when you expected it fully visible, you're probably on auto-out when you wanted auto-in (or vice versa) - re-read the two definitions above, they're easy to swap in your head since both start with "auto."
If the background color isn't changing the way you expect, remember there are two separate pickers (b_color and bjimg_color) - you may be adjusting the one that isn't driving the effect you're looking at. As with the rest of ComfyUI-Apt_Preset: it's a large, actively-updated pack, and at least one user has reported an IMPORT FAILED error at ComfyUI startup after installing it. Check the console log if this node doesn't appear after install.
Inputs (17)
| Name | Type | Default | Description |
|---|---|---|---|
| bimg | IMAGE | — | |
| bmask | MASK | — | |
| b_color | COMBO | blue | 7 options: bimg, black, white, red, green, blue, +1 |
| b_extrant_to_block | BOOLEAN | true | — |
| f_extrant_to_block | BOOLEAN | true | — |
| f_smoothness | INT | 10–150 | — |
| f_opacity | FLOAT | 1.000–1 | — |
| bjimg_color | COMBO | blue | 6 options: black, white, red, green, blue, gray |
| fimgopt | IMAGE | — | |
| fmaskopt | MASK | — | |
| f_x_offsetopt | INT | 0-500–500 | — |
| f_y_offsetopt | INT | 0-500–500 | — |
| f_scaleopt | FLOAT | 1.000.01–5 | — |
| scale_modeopt | COMBO | auto-in | 5 options: None, width_align, height_align, auto-in, auto-out |
| align_modeopt | COMBO | center | 9 options: center, top_center, bottom_center, left_center, right_center, top_left, +3 |
| f_rotopt | INT | 0-180–180 | — |
| image_outputopt | COMBO | Preview | 4 options: Hide, Preview, Save, Hide/Save |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| composed_image | IMAGE | — |
| new_background | IMAGE | — |
| foreground_layer | IMAGE | — |
| foreground_mask | MASK | — |