Mask Rectangular Area 🦾
A rectangle mask, specified by the numbers
- MASKS
Mask Rectangular Area draws a rectangle. That sounds too simple to need a node, until you need a rectangle mask - a region where a model is allowed to generate (or forbidden from touching) - and you need it to be exact, reproducible, and numerically aligned to your canvas. That's what this is: a mask tensor with a solid white rectangle at coordinates you type in.
This is the same idea as ComfyUI's built-in rectangle mask tools, but standalone and pixel-addressable: you specify x, y, width, height for the rectangle and image_width/image_height for the canvas it lives on, and out comes a mask. If you've ever set up regional prompting or a "keep this region untouched" inpaint workflow with a fixed rectangle - a text box, a face area, a logo zone - you know why you want it.
How it works
Under the hood it creates a zeroed tensor of image_height × image_width, then sets the slice from (x, y) to (x+width, y+height) to 1. The result is a single-channel MASK. Slicing past the edge is safe - torch just clips it - so a rectangle that hangs off the canvas gets cut at the boundary rather than erroring.
The step on every input is 64, which is deliberate: it keeps rectangles aligned to the multiples ComfyUI's latent sizes and many models prefer. If you need sub-64 precision, you can still type in an exact number; the step only affects dragging.
The inputs that matter
x,y(required, default 0) - top-left corner of the rectangle.width,height(required, default 512) - rectangle size.image_width,image_height(required, default 512) - the canvas dimensions the mask must match downstream. This is the one beginners get wrong: the mask is only useful if these match the image/latent you're conditioning.
Output: MASKS (a MASK tensor).
Install
Part of ComfyUI-Beyond_nodes. ComfyUI Manager → search "Beyond_nodes" → install → restart. Manual:
cd ComfyUI/custom_nodes
git clone https://github.com/beyondprompting/ComfyUI-Beyond_nodes
Restart. No extra dependencies.
Common issues
- The mask is the wrong size / doesn't line up.
image_width/image_heightdefine the mask's dimensions - they must equal your actual image dimensions, not the rectangle's. A 512×512 mask on a 1024×1024 image is useless. - It's a hard edge and I want a soft one. This node doesn't blur. Pipe the mask through a Blur Mask node, or pair it with the pack's MaskBoundingBox, which adds padding and blur for exactly this.
- I want a mask from an existing image's subject, not a rectangle. Different tool - use a segmentation/SAM workflow. This node is for when you know the geometry up front.
Rectangle masks are the boring workhorse of controlled generation: fixed regions, reproducible results, no model involved. When the region you care about is a rectangle, this is the fastest way to build it.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| x | INT | 00–4096 | — |
| y | INT | 00–4096 | — |
| width | INT | 5120–4096 | — |
| height | INT | 5120–4096 | — |
| image_width | INT | 51264–4096 | — |
| image_height | INT | 51264–4096 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MASKS | MASK | — |