Crop by Margins (Image)
The boring crop node you'll reach for constantly
- image
- IMAGE
What it's for
Not every crop needs a subject detector. Sometimes you know the bottom 120 pixels are a scanner's plastic bed, or you want a test crop of one region, or you need a mask and its image cut to matching coordinates. For that, you want a node that does exactly what you said and nothing clever.
Crop by Margins (Image) takes four nonnegative integers and slices the tensor. No resizing, no interpolation, no subject logic, no fill - the output is literally a sub-rectangle of the input, in the original dtype. That's the feature. A crop node that also "helps" is a crop node that changes your pixels when you weren't looking.
Inputs, and the one that surprises people
Required: image, plus left_px, top_px, right_px, bottom_px (0–16384 each), and snap_multiple (1–512).
Crops are inward only - there's no negative padding, and if you ask it to remove more pixels than exist it raises an explanatory error instead of clamping silently. Output is a single IMAGE.
snap_multiple is the interesting widget. It rounds the remaining width and height down to a multiple, keeping the top-left corner where it is, which means the extra pixels come off the right and bottom edges. Default is 1, i.e. off. Set it to 2 and an awkward 1081×803 becomes 1080×802. Set it to 8 or 16 when you need a grid the model's VAE won't re-round on you, or to 32 when you're feeding something that wants 32-alignment and you don't have a better stage for it.
That's also the honest limit: this is a manual tool. If you want the crop chosen for you - around a subject mask, inside a protected region, at the exact aspect family and resolution an editor wants - that's Smart Photo Prepare, and this node isn't a substitute. It's what you reach for when you already know the numbers.
What it's actually good at
- Trimming known chrome: a scanner bed, a UI bar, a sprocket edge, a fixed caption band.
- Keeping an image and its mask on identical coordinates. Apply the same four values on the mask node and the grids stay aligned; get this wrong and your inpaint edge lands somewhere else entirely.
- Test crops. Pulling one face region out to iterate on a detail pass without re-running the whole graph.
- Making a dimension even before a node that assumes it. Cheaper than an arbitrary resize and it doesn't touch the pixels.
Load Image + Source Info ─┬─> Crop by Margins (Image) ─> your pipeline
└─> (segmenter) mask ─> Crop by Margins (Mask) with the same four values
Where people get burned
The naming. The old 1.x documentation for this family described fill colours, negative padding and an enforce-even control; the current docs state plainly that those never existed in the shipped engine, and that the previous description was inaccurate. If you find a tutorial promising a fill colour here, it's describing a node that isn't installed.
Second: snap_multiple only ever removes pixels, and only from the right and bottom. It cannot centre your result, and it cannot pad to reach a multiple. If you need to add pixels to hit a grid, you want a pad node and then this one, in that order.
Third, on batch inputs: this slices each member identically, which is usually what you want for a batch shot the same way, and obviously wrong if the images have different framing. Crop before batching, or don't batch.
Install
ComfyUI Manager → search PortraitUtils (publisher heyburns, GPLv3), or:
cd ComfyUI/custom_nodes
git clone https://github.com/heyburns/PortraitUtils
/path/to/ComfyUI/venv/bin/python -m pip install -r PortraitUtils/requirements.txt
The pack installs numpy, Pillow, opencv-python-headless and tifffile into ComfyUI's Python environment; install only one OpenCV variant there. Restart the ComfyUI server after the install - a browser refresh won't register new nodes. This node itself needs no models and no downloads.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| left_px | INT | 00–16384 | — |
| top_px | INT | 00–16384 | — |
| right_px | INT | 00–16384 | — |
| bottom_px | INT | 00–16384 | — |
| snap_multiple | INT | 11–512 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |