Yc Image Smart Crop
Crop an image and get the map of where you cropped it
- image
- image
- mask
The name oversells it. "Smart Crop" sounds content-aware - an AI deciding what's worth keeping. It isn't. This node crops a fixed number of pixels off each edge and, more importantly, hands you back a mask that records what you kept and what you cut. The mask is the entire reason it's worth a slot in your graph, because it means you can crop now and restore exactly later.
What it's actually for
You're fixing a detail - a face, a hand, a bit of clothing - and you know from the inpainting playbook that the trick is not to run the whole frame. Crop tight around the problem, regenerate at full resolution where the pixels actually matter, then stitch back. That crop-and-stitch loop is one of the most reliable inpainting patterns in ComfyUI, and this node is a cheap way to do the crop half while keeping the bookkeeping straight. The image output is the crop; the mask output is your receipt.
How it works
It processes each image in the batch: convert to PIL, cut left, top, right, bottom pixels off the respective edges, convert back. Nothing clever. The mask is the useful part - it's drawn at the original image size, with the region you kept as white and everything you cut as black. Flip invert_mask and the kept area goes black instead. The mask's job is to tell a downstream inpaint or composite node exactly where the crop used to sit.
The inputs that matter
There are only five, and you'll set four of them:
- left / top / right / bottom - pixels to cut off each side (default 50 each). The crop region is
width - left - rightbyheight - top - bottom, so don't over-ask. - invert_mask - keep the mask white-on-kept, or flip it.
Outputs: the cropped image and the original-size mask. Wire the mask into anything that takes a MASK - YCImageSmartPad and YCImageUntile in this same pack are natural partners if you want to restore the original bounds afterward.
Install
This ships in the ComfyUI-YCNodes pack. Easiest route is ComfyUI Manager - search for "ComfyUI-YCNodes", install, restart. Or by hand:
cd ComfyUI/custom_nodes
git clone https://github.com/yichengup/ComfyUI-YCNodes
Then restart ComfyUI. The pack pulls in torch, numpy, pillow, opencv-python, and scipy - no model downloads, no weights. Note the README's own clone line still points at a placeholder URL; the repo above is the real one.
Where people get burned
- Cropping past the edge throws an error. If
left + right >= image width(same for height), the node raises aValueErrorand the whole graph stops. Keep totals comfortably inside the image. - The node silently vanished from your menu. The pack's
__init__.pyimportscv2at module level, and ifopencv-pythonisn't installed the entire image module fails to load - it just gets skipped with a❌ Failed to load nodeline in the console. Check your startup log before assuming a conflict;pip install opencv-pythonfixes the most common cause.
It's a narrow tool, and "Smart" is doing a lot of advertising for a plain crop. But when you need a crop that carries its own coordinates, it beats doing it by hand.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| left | INT | 500–1000 | — |
| top | INT | 500–1000 | — |
| right | INT | 500–1000 | — |
| bottom | INT | 500–1000 | — |
| invert_mask | BOOLEAN | false | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |