ComfyUI Node

Crop Image

Cut, don't stretch

By Stibo·Created 7 months ago·Updated 7 days ago· 11
Crop Image
  • image
  • IMAGE
◄width512►
◄height512►
◄crop_widthcenter►
◄crop_heightcenter►

Every crop node out there is quietly a resize node wearing a hat. This one isn't: it cuts pixels out and leaves the rest exactly where it was. No scaling, no aspect-ratio math, no "did it stretch my faces this time."

That's a smaller feature than it sounds, and more useful. Cropping is how you trim a letterboxed video frame, pull a head-and-shoulders square out of a 4-megapixel Flux.2 render before a detail pass, or chop a border artifact off the edge of an upscale - all cases where resizing is the wrong answer.

How it works

Take the image, take your target width and height, and take two position dropdowns. Width and height are handled independently, which is the actual selling point: crop_width is left, center or right, and crop_height is top, center or bottom. You can shave the left edge and the bottom third in one node, which is usually two or three nodes anywhere else.

The center position is a floor division of the leftover space, so an odd difference leaves an extra pixel on one side. You won't see it, but it's why a "centered" crop on odd dimensions isn't perfectly symmetric.

Two behaviors worth knowing because they're silent:

  • Asking for more than the image has just returns the whole image. The crop size is clamped to the source dimensions. Type 2048 into width on a 1024-wide image and you get 1024, no error, no padding.
  • It works on batches. The same crop window is applied to every frame in the tensor, so a 60-frame video batch comes out still 60 frames and consistently framed. That's what makes it usable before a video upscale or an img2img pass over frames.

Inputs and outputs

  • image - one image or a batch.
  • width - default 512. 0 keeps the original width.
  • height - default 512. 0 keeps the original height.
  • crop_width - left, center, right.
  • crop_height - top, center, bottom.

One output: IMAGE, cropped. No width/height outputs, no mask, no passthrough of the original.

The two zeros are the nicest part of the design: set width: 0 and only crop vertically, or height: 0 to only trim the sides. Changing a 16:9 render into a square without touching the horizontal framing is two widgets instead of a calculator.

Installing it

ComfyUI Manager → search Nifty Nodes, or:

cd ComfyUI/custom_nodes
git clone https://github.com/Stibo/comfyui-nifty-nodes

Then restart. This node needs nothing beyond the pack - the declared dependencies (color-matcher, imageio-ffmpeg) belong to other nodes in it. This was added in the pack's 2.2.0 release, along with the batch loop pair and the Flux.2 sampler. The pack is authored against ComfyUI's V3 node API and the README says it's tested on frontend 1.39, untested on Nodes 2.0.

Where people get burned

  • Cropping and upscaling are different jobs. If you wanted a bigger image, crop never does that - pair it with Resize Image or the pack's upscale node. And if you're cropping to change aspect ratio before an upscale, remember you're discarding pixels the model will have to invent back.
  • Center is a crop, not a resize. A "center crop to 1024×1024" of a wide image deletes the sides. If those sides contain the subject's shoulder, that's on you, not on the node.
  • Cropping before a detail pass changes what the model sees. For faces especially, a tighter crop means the detail pass is working on a bigger face at the same resolution - better results, but a different composition than the one you approved.
  • Video batches keep the same window for every frame. There's no per-frame tracking here. If your subject walks around the frame, you want a mask-driven crop instead.
Categorynifty/media

Inputs (5)

NameTypeDefaultDescription
imageIMAGEImage or image batch to crop.
widthINT5120–16384Target crop width in pixels. 0 keeps the original width unchanged.
heightINT5120–16384Target crop height in pixels. 0 keeps the original height unchanged.
crop_widthCOMBOcenterHorizontal crop position.
crop_heightCOMBOcenterVertical crop position.

Outputs (1)

NameTypeDescription
IMAGEIMAGE—