Nodes/ComfyUI-KYNode/Crop Image by XYWH
ComfyUI Node

Crop Image by XYWH

Crop by exact numbers, with divisible-size safety

By yorkane·Created 2 years ago·Updated 6 months ago· 10
Crop Image by XYWH
  • image
  • IMAGE
x0
y0
width512
height512
divisible_by1

The straightforward version of image cropping: you know the exact top-left corner and size of the region you want, so you type in x, y, width, height, and get that rectangle cut out of the image. Its sibling node, KY_ImageCropByBBox, does the same job but takes a BBOX object from a detector - reach for this one when you already know your numbers, that one when a detection node upstream is producing them for you.

The one setting that's easy to skip and shouldn't be

divisible_by (default 1, max 128) is the detail that separates this from a naive crop. Diffusion models and their VAEs generally want image dimensions that are cleanly divisible - SD/SDXL's VAE wants multiples of 8, and some newer architectures want 16, 32, or 64. Crop to an arbitrary size like 507×713 and feed that straight into a sampler, and you can get artifacts or outright errors at the edges. Set divisible_by to whatever your model family needs (8 is the safe common denominator) and the node adjusts the crop size to land on a clean multiple, instead of making you do that math by hand every time.

Inputs and output

Required: image (the IMAGE to crop), x/y (top-left corner, both defaulting to 0), width/height (defaulting to 512, minimum 64), and divisible_by (1 to 128). One output: the cropped IMAGE.

This is a manual-coordinate tool, not a detection tool - it doesn't find anything in the image for you. It pairs naturally with a detect-crop-refine pipeline (the same pattern Impact Pack's FaceDetailer automates end to end) if you want to insert your own logic between detection and cropping - say, computing coordinates from a KY_MathExpression node, or deciding what to crop based on a regex match on a filename - rather than letting a single automated node do the whole loop.

Installing it

ComfyUI Manager: search ComfyUI-KYNode, install, restart. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/yorkane/ComfyUI-KYNode

Restart ComfyUI. No external dependencies beyond what ComfyUI already has - straightforward tensor slicing.

Common issues

If x + width or y + height runs past the actual image's dimensions, the schema doesn't document what happens - it's not clamped or validated as far as the inputs show, so keep your numbers inside the real image size rather than assuming the node will save you from an out-of-bounds crop.

If you're getting weird seams or artifacts once the crop goes through a sampler or gets composited back, check divisible_by first - a mismatch between your crop's actual dimensions and what your model expects is the single most likely cause, and it's an easy one to overlook since the crop itself will still "work" and just produce a slightly wrong-sized region.

And remember the minimum width/height is 64 - you can't crop a smaller region than that with this node, which is a sane floor given how small a useful diffusion-model input region gets before results turn to noise anyway.

CategoryKYNode/image

Inputs (6)

NameTypeDefaultDescription
imageIMAGE
xINT00–999999
yINT00–999999
widthINT51264–999999
heightINT51264–999999
divisible_byINT11–128

Outputs (1)

NameTypeDescription
IMAGEIMAGE