Create Rect Mask
A precise rectangle mask, no painting required
- copy_image_size
- IMAGE
Sometimes you don't need ClipSeg, SAM, or any kind of detection to get a mask - you already know exactly where the region should be, because you're building it programmatically or you just want a clean, reproducible rectangle. Create Rect Mask builds one from numbers: an origin corner, an offset, and a width and height. No painting, no image analysis, fully deterministic and easy to drive from other numeric nodes upstream.
The main decision is mode. percent treats x, y, width, and height as percentages of the target image (50.0 means half the image), which is the resolution-independent option - build the rectangle once and it scales correctly whether you feed it a 512px or 2048px image. pixels treats those same four values as literal pixel measurements, which is more precise when you know exactly where something needs to sit (compositing a logo at a fixed position, say) regardless of the overall image size.
The inputs that matter
- mode -
percentorpixels. - origin - which corner
x/yare measured from:topleft,bottomleft,topright, orbottomright. This matters more than it sounds like - a rectangle built fromtopleftand one built frombottomrightwith the same numbers land in completely different places. - x, y - the offset from that origin.
- width, height - the rectangle's size.
- image_width, image_height (default 512 each) - the canvas size to build the mask against, only used if
copy_image_size(optional) is left unwired. - copy_image_size (optional) - wire an actual image in here and the mask matches its dimensions automatically, overriding
image_width/image_height. This is the more robust option any time you already have an image in the graph to match against - it removes an entire class of "I built the mask at the wrong resolution" mistakes.
Output is the resulting rectangular mask.
Installing it
Create Rect Mask ships as part of Masquerade Nodes. Get it via ComfyUI Manager (search "Masquerade Nodes") or manually: cd ComfyUI/custom_nodes && git clone https://github.com/BadCafeCode/masquerade-nodes-comfyui, then restart ComfyUI. Pure geometry, no models, no extra dependencies - it's one of the simplest nodes in the pack to install and the least likely to break.
Common issues
The most common surprise is a rectangle landing in the wrong place or the wrong scale, and it's almost always origin or mode mismatched with what you were assuming - double-check origin first (a bottomleft-anchored rectangle with positive y grows upward from the bottom, not downward from the top), then confirm you're not mixing percent-scale thinking with pixels mode or vice versa. If the mask's resolution doesn't match the image you're compositing it onto, that's a sign copy_image_size was left unwired and the fallback image_width/image_height (512x512 by default) didn't match your actual canvas - wire copy_image_size to your real image whenever one is available in the graph, rather than hand-typing dimensions that can silently drift out of sync.
Inputs (9)
| Name | Type | Default | Description |
|---|---|---|---|
| mode | COMBO | 2 options: percent, pixels | |
| origin | COMBO | 4 options: topleft, bottomleft, topright, bottomright | |
| x | FLOAT | 00–1048576 | — |
| y | FLOAT | 00–1048576 | — |
| width | FLOAT | 500–1048576 | — |
| height | FLOAT | 500–1048576 | — |
| image_width | INT | 51264–1048576 | — |
| image_height | INT | 51264–1048576 | — |
| copy_image_sizeopt | IMAGE | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |