Nodes/ComfyUI-Rect/Rect / Crop
ComfyUI Node

Rect / Crop

The two-input node that ends coordinate guesswork

By jtrue·Created about a year ago·Updated about a year ago· 3
Rect / Crop
  • image
  • rect
  • image

This is the simplest node in the ComfyUI-Rect pack, and that's the point. Rect / Crop takes an image and a rectangle and hands back the cropped pixels. No sliders, no modes, no feather, no hidden state. Two inputs, one output, done - which is refreshing in an ecosystem where every second node ships with seventeen tabs.

How it works

Under the hood it's a torch tensor slice: image[:, y:y+h, x:x+w, :], executed on whatever rectangle you feed it. The one piece of real engineering is the clamping - the top-left corner is forced inside the image and the width/height are trimmed so the slice never runs off the edge or returns an empty crop. Hand it a rectangle that hangs half off the canvas and it silently gives you the part that fits instead of crashing or returning black. It also handles batched images ([B, H, W, C]) the same way it handles a single one, so a crop on a batch of frames works without you thinking about it.

The one thing you need to know

There's really only one input that matters, and it's rect - the RECT object. The normal way to get one is to add the pack's Rect / Select node, draw a box over your image with the marching-ants popup, and wire its rect output straight in. That's the whole workflow the pack is built around, and it's why this node exists at all: it's the consumer for a selection you made with a mouse instead of a calculator.

What you'd actually use it for

  • Region upscaling. Crop a face or a detail region, run it through an upscaler at its own resolution, stitch it back - classic crop-and-stitch territory.
  • Feeding a region to another model. Grab just the area you care about so a detector or a depth preprocessor only has to look at the part that matters.
  • Checking a crop before you commit. Preview exactly what a mask or fill is going to cover.

The output image is a normal IMAGE tensor, so it wires into anything that accepts one - an upscale model, a VAE encode, a Save Image.

Install

ComfyUI Manager (search "ComfyUI-Rect"), or manually:

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

Restart, and you're done. There's no requirements.txt and no model download - the whole pack is stock PyTorch, which is worth appreciating when you compare it to the average custom-node dependency list. If a downloaded workflow complains about a missing Rect / Crop, this is what Manager is for.

Gotchas

Honestly, not many. If the rectangle comes in as something that isn't a dict with x/y/w/h, the node falls back to a 1×1 crop at the top-left rather than throwing - you'll notice the "bug" long before any crash. The one thing that catches people: the rect input is the pack's custom RECT type, which only Rect / Select produces. If you have a selection from somewhere else as plain ints, use a Select node's x/y/w/h outputs and route them through this pack's RectSelect to get a proper RECT - or just let RectSelect be the one place you draw boxes.

It's a boring utility node that does exactly one thing well. Sometimes that's exactly what a workflow needs.

CategoryRect

Inputs (2)

NameTypeDefaultDescription
imageIMAGE
rectRECT

Outputs (1)

NameTypeDescription
imageIMAGE