Nodes/ComfyUI-Rect/Rect / Select
ComfyUI Node

Rect / Select

Draw your rectangle instead

By jtrue·Created about a year ago·Updated about a year ago· 3
Rect / Select
  • image
  • rect
  • x
  • y
  • w
  • h
x0
y0
w256
h256

Vanilla ComfyUI has a special kind of sadism for anyone who needs a crop region: you eyeball the image, guess the pixel coordinates in your head, and type them into a number widget, then rerun and discover you were forty pixels off. Rect / Select is the fix. It's the headline node of the ComfyUI-Rect pack and the reason the whole thing exists - a button on the node opens a popup where you drag a box over your actual image and the numbers write themselves.

How it works

The Python side of this node is almost boringly simple. It reads the height and width off your image tensor, clamps whatever x/y/w/h values you've set to the image bounds (so nothing ever overflows), and hands back a rectangle. All the interesting machinery lives in the JavaScript that ships with the pack. When the node appears on your canvas, an "Open Rect / Select" button gets attached to it. Click it and a modal pops up showing the image wired into the image input. Drag out a selection, watch the classic dashed "marching ants" border, hit Apply Rect, and the overlay writes x, y, w, and h back into the node's widgets. The graph re-executes and everything downstream gets your selection.

That round-trip - overlay writes widgets, widgets feed the node - is why it feels magic and also why it's fragile in one specific way (see troubleshooting).

Inputs and outputs

You set four things, and the front-end does it for you:

  • image - the IMAGE the box lives on. It has to be connected for the overlay to have something to render.
  • x, y, w, h - the rectangle, in image pixel space. The overlay fills these in; you can also type them directly, which is handy when you're replaying a saved workflow.

The outputs are the clever part, because it emits both a rect (the pack's custom RECT type, a JSON-like {x, y, w, h} object) and the four scalars x/y/w/h as separate INTs. The RECT feeds this pack's Crop/Mask/Fill nodes; the four ints exist so you can wire the same selection into other packs' crop or region nodes that just want plain numbers. It's a compatibility hack, and a good one.

Why you'd reach for it

This is the seed node for any workflow that cares where a box is: a face region you want to upscale separately, a region to mask for inpainting, an area you need to keep out of a redaction. The bundled demo workflow is the whole pitch - Load Image into Rect / Select, then fan the rect output to Rect / Crop, Rect / Mask, and Rect / Fill. Compare that to typing x=763, y=309, w=1378, h=749 from the demo file by hand and you'll feel the difference instantly.

Install

ComfyUI Manager (search "ComfyUI-Rect") or the manual way:

cd ComfyUI/custom_nodes
git clone https://github.com/jtrue/ComfyUI-Rect

Then restart ComfyUI. There are no model downloads and, unusually for a custom node, no requirements.txt - it's pure PyTorch, which ComfyUI already has. This is the anti-dependency-hell node; if this is the first pack you've installed, enjoy how painless that is, because it doesn't last.

Gotchas

  • Button missing. The README's one real troubleshooting tip: if "Open Rect / Select" doesn't show up, it's cache. Open ComfyUI with ?nocache=1 in the URL.
  • No image in the selector. The overlay needs the image input connected. If it's not, you get a toast telling you exactly that. And because the overlay renders the upstream file, it works best straight off a Load Image node rather than some exotic source.
  • RECT is this pack's type. Only RectSelect emits it, so a rect input elsewhere in a downloaded workflow means that workflow expects this pack. The four INT outputs are the escape hatch when you want to use the selection elsewhere.

If you've ever wished ComfyUI had a "select with your mouse" for cropping, this is that wish, delivered small and dependency-free.

CategoryRect

Inputs (5)

NameTypeDefaultDescription
imageIMAGE
xINT00–65535
yINT00–65535
wINT2561–65535
hINT2561–65535

Outputs (5)

NameTypeDescription
rectRECT
xINT
yINT
wINT
hINT