Nodes/Crop To Center/Crop To Center
ComfyUI Node

Crop To Center

The node that crops to the middle so you don't have to

By leewinder·Created 11 months ago·Updated 11 months ago· 0
Crop To Center
  • image
  • cropped_image
target_width512
target_height512
center_offset_x0
center_offset_y0

Crop To Center is about as minimal as a ComfyUI node gets: feed it an image, tell it how big you want the result, and it crops straight out of the middle. No AI, no model files, no API key, no heavy dependency that can fight your other nodes. If you've ever sat in the middle of a workflow doing crop-box math by hand, this is the node that turns that whole step into one number.

Where it actually fits

The classic reason to reach for it is the "generate at a trained ratio, then crop" pattern. Diffusion models are picky about their native resolution - SDXL only really likes a handful of discrete aspect ratios, and a video model like Wan 2.2 behaves noticeably better when its input frame matches what it was trained on (16:9-ish, tiles of 16). So the routine is: generate at a ratio the model likes, upscale if you need the headroom, then crop the middle to your final ratio. When the target is 1920x1080 but the model wanted 1344x768, something has to slice the middle out. That's this node's job, and it's the honest framing: this is a centered crop with an offset, nothing cleverer, and it doesn't need to be.

How it works

It removes equal amounts from all four sides around the image's center point, keeping the requested dimensions exact. The center offset moves the crop region around; push it far enough that the crop would run off the edge and it clamps, staying as close to your requested center as it can while still honoring the target size. So the output is always exactly target_width × target_height, and the offset is a preference, not a demand.

The inputs that matter

There are five, and four of them are numbers:

  • image - the IMAGE you're cropping.
  • target_width / target_height - both default to 512, both up to 8192. These are the final dimensions; see the gotcha below.
  • center_offset_x - positive moves the crop right, negative left.
  • center_offset_y - and here's the trap: positive moves up, negative moves down. Most image editors treat y as growing downward, so this is backwards from your intuition. One misplaced sign and your subject drifts the wrong way.

The output is a single cropped_image (IMAGE), which wires straight into whatever's next - a save node, an upscaler, a video model's image input.

The one real constraint: target dimensions must be less than or equal to the source. Ask for something bigger and the node can't invent pixels, so it will refuse or misbehave. Crop down, or upscale first.

Installing it

ComfyUI Manager is the easy path: Manager → Install Custom Nodes, search for Crop To Center, install, restart. Or the manual route:

cd ComfyUI/custom_nodes
git clone https://github.com/leewinder/comfyui-crop-to-center.git

then restart ComfyUI. That's the whole install - the README lists no runtime dependencies and no model downloads. The dev setup (pyenv, pytest, pylint) is only if you want to contribute, and it's worth remembering this is single-purpose, single-node code from an individual maintainer (leewinder), not a big pack with a bus-factor cushion.

Troubleshooting

The main failure mode is the node not showing up after install - and the fix is boring but real: restart ComfyUI completely, not just reload the frontend. If you're hitting the "target bigger than source" wall, that's a workflow order problem, not a bug: upscale first, then crop. And note the license is Creative Commons NonCommercial - fine for personal use, but don't wrap this in a paid product without thinking about it.

One honest caveat: if what you actually want is a crop that follows the subject - auto-framing a face or object wherever it sits in the image - this isn't that. That's SAM / segment-anything territory, a whole different node. Bigger suites like WAS Node Suite can crop too. But for a deterministic, batch-safe middle-crop, this is the one I'd reach for: it does exactly one thing, does it without dependencies, and never surprises you.

Categoryimage/transform

Inputs (5)

NameTypeDefaultDescription
imageIMAGE
target_widthINT5121–8192
target_heightINT5121–8192
center_offset_xINT0-4096–4096
center_offset_yINT0-4096–4096

Outputs (1)

NameTypeDescription
cropped_imageIMAGE