Nodes/zsq_prompt/Image Crop
ComfyUI Node

Image Crop

Crop an image without guessing pixel coordinates

By windfancy·Created 2 years ago·Updated 5 months ago· 2
Image Crop
  • image
  • IMAGE
  • x
  • y
width256
height256
position
x_offset0
y_offset0

Crop is one of those operations ComfyUI core doesn't make as friendly as it could. Image Crop (imageCrop) from the zsq_prompt pack fixes the annoying part: instead of typing raw x/y coordinates, you pick one of nine anchor positions (top-left, top-center, center, right-center, and so on) and let the node figure out the math. If you've ever needed to slice a region out of a generated image - a face area, a panel, a chunk to feed back into img2img - this is the friendly way to do it.

How it works

You tell it the crop width and height, pick a position anchor, and it calculates the crop origin so the box lands at that spot. The actual x and y coordinates it chose are returned alongside the cropped image, which is a genuinely nice touch: you always know exactly where the crop came from, so you can composite it back later.

Two safety behaviors worth knowing:

  • Width and height are clamped to the source image, so asking for a 2000px crop out of a 1024px image just gives you the full image rather than an error.
  • The x_offset / y_offset inputs let you nudge the box away from the anchor - including negative offsets. If you push it off-canvas, the node clamps back to the edges instead of exploding.

Inputs and outputs that matter

  • image - the IMAGE to crop from.
  • width / height - crop box size, step of 8 by default (handy for keeping dimensions SDXL-friendly).
  • position - the nine-anchor dropdown. This is the one you'll actually touch.
  • x_offset / y_offset - fine-tuning. Leave at 0 unless you need it.
  • Outputs: IMAGE (the crop), plus x and y (the origin). Wire x/y into a composite or paste node if you want to put the crop back where it came from.

Where this fits in a workflow

The classic use is pre-processing for img2img or ControlNet: crop a face region, run it through a second pass, then composite the refined region back using the x/y outputs. It's also handy for working with grids - slice one cell out of a 2x2 generated batch for closer inspection. If your plan is "crop to a fixed size, then scale," the pack's imageResize and imageScaleDown nodes chain right after this one.

Installing zsq_prompt

All the nodes in this pack install together. In ComfyUI Manager, search zsq_prompt and install, or:

cd ComfyUI/custom_nodes
git clone https://github.com/windfancy/zsq_prompt

Restart ComfyUI afterward. The pack's requirements are heavy - transformers, opencv-python, opencv-contrib-python, scikit-image, timm, onnx, ultralytics - so expect a real install, and don't panic if Manager flags a "conflicting with zsq_prompt" message on some downloaded workflow; that's Manager's dependency overlap detection being noisy, and it's misleading until you've actually installed the pack. No model downloads are needed for this node.

Gotchas

  • This is a hard pixel crop, not a resize. If your crop size doesn't match the aspect ratio of the region, you get a smaller box, not a stretched one.
  • The x/y outputs are the crop origin in the original image's coordinate space - keep that in mind if you're pasting into a differently-sized canvas.
  • One light warning: it operates per tensor, so feed it a single image (batch 1) unless you intentionally want the same crop applied to every frame of a batch.
CategoryZSQ/Image

Inputs (6)

NameTypeDefaultDescription
imageIMAGE
widthINT2560–16384
heightINT2560–16384
positionCOMBO9 options: top-left, top-center, top-right, right-center, bottom-right, bottom-center, +3
x_offsetINT0
y_offsetINT0

Outputs (3)

NameTypeDescription
IMAGEIMAGE
xINT
yINT