Nodes/Masquerade Nodes/Create Rect Mask
ComfyUI Node Runs on cloud

Create Rect Mask

A precise rectangle mask, no painting required

By BadCafeCode·Created 3 years ago·Updated 2 years ago· 479
Create Rect Mask
  • copy_image_size
  • IMAGE
mode
origin
x0
y0
width50
height50
image_width512
image_height512

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 - percent or pixels.
  • origin - which corner x/y are measured from: topleft, bottomleft, topright, or bottomright. This matters more than it sounds like - a rectangle built from topleft and one built from bottomright with 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.

CategoryMasquerade Nodes

Inputs (9)

NameTypeDefaultDescription
modeCOMBO2 options: percent, pixels
originCOMBO4 options: topleft, bottomleft, topright, bottomright
xFLOAT00–1048576
yFLOAT00–1048576
widthFLOAT500–1048576
heightFLOAT500–1048576
image_widthINT51264–1048576
image_heightINT51264–1048576
copy_image_sizeoptIMAGE

Outputs (1)

NameTypeDescription
IMAGEIMAGE