Mask Bounding Box Aspect Ratio
Crop to a mask at the ratio you want
- image
- mask
- image
- mask
- mask_blurred
- x
- y
- width
- height
This is an inpainting/detailing helper. Give it a mask, and it finds the tight rectangle around the masked region, expands that rectangle to a target aspect ratio, and hands you back the cropped image plus the crop's exact coordinates. That last part is the point: because it returns the x, y, width, and height it used, you can process the crop (inpaint it, run a detailer on it, upscale it) and then paste it back into the original image at precisely the right spot. It's the "crop → fix → stitch" pattern that makes region-based editing efficient instead of re-rendering the whole frame.
It ships in RES4LYF (by ClownsharkBatwing) - a pack mostly famous for flow-matching samplers, but which carries workflow utilities too. Tellingly, this node's category is essentials/mask, the naming convention of the popular ComfyUI Essentials pack, so if you've used that ecosystem it'll feel familiar.
Why crop to an aspect ratio at all
Because models generate best at the resolutions and shapes they were trained on. A raw mask bounding box is whatever shape the masked area happens to be - often a weird sliver. Forcing it to a sane aspect ratio (1:1, 3:4, 16:9) before you sample into it means the inpaint or detailer works on a well-proportioned tile the model actually likes, which is the difference between a clean fix and a warped one. The padding gives the model context around the edit so the result blends; the blur softens the mask so the seam disappears when you composite back.
The inputs and outputs
- mask (optional
MASK) - the region to bound. This is what drives the crop. - image (optional
IMAGE) - the source to crop from. - aspect_ratio (default 1.0) - the target ratio the box is expanded to. 1.0 is square; set it to match your inpaint tile.
- padding (default 0) - pixels added around the box, for blend context. A little padding almost always helps.
- blur (default 0) - softens the mask edge; feeds the separate
mask_blurredoutput. - transpose (default false) - flips the ratio's orientation (portrait ↔ landscape) when the region's shape calls for it.
Outputs: image (the crop), mask and mask_blurred (sharp and softened, for compositing), and x, y, width, height - the four integers you feed a paste/stitch node to put the processed crop back exactly where it came from.
Installing it
ComfyUI Manager: search RES4LYF, install, restart. Or manually: cd ComfyUI/custom_nodes && git clone https://github.com/ClownsharkBatwing/RES4LYF, then cd RES4LYF && pip install -r requirements.txt in your venv (portable ComfyUI uses its embedded pip). Restart, hard-refresh F5. No models.
Where people get burned
- Forgetting to stitch back. The x/y/width/height outputs exist so you can composite the fixed crop into the original. Skip that and you've just got a floating cropped patch.
- Zero padding, hard seam. With
padding0 andblur0 the pasted region can show a visible edge. Add a few px of padding and a little blur (use themask_blurredoutput for the composite) and it vanishes. - Ratio vs region mismatch. A tall thin mask forced to 1:1 grabs a lot of surrounding image. Either pick an aspect ratio close to the region's real shape or use
transposeso the box grows the sensible way. - Two nodes, same name. Because it lives under
essentials/mask, workflows built for the actual ComfyUI Essentials node may resolve to a different one. If a graph specifically wants the RES4LYF version, install RES4LYF.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| padding | INT | 00–4096 | — |
| blur | INT | 00–256 | — |
| aspect_ratio | FLOAT | 1.000.01–10 | — |
| transpose | BOOLEAN | false | — |
| imageopt | IMAGE | — | |
| maskopt | MASK | — |
Outputs (7)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |
| mask_blurred | MASK | — |
| x | INT | — |
| y | INT | — |
| width | INT | — |
| height | INT | — |