Nodes/Y7Nodes for ComfyUI/Y7 Crop to Nearest Multiple
ComfyUI Node

Y7 Crop to Nearest Multiple

The crop node that stops 'dimensions must be divisible by 16' errors

By yushan777·Created about a year ago·Updated 4 days ago· 8
Y7 Crop to Nearest Multiple
  • image
  • crop_preview
  • cropped_image
  • info
multiple16
h_cropcenter
v_cropcenter

"Image dimensions must be divisible by 16." If you've ever hit that error from a VAE or an upscaler, you know the drill: your pipeline produced a 1021×767 image and now everything downstream is refusing to play ball. Y7 Crop to Nearest Multiple is the fix - it crops an image so both dimensions land on the nearest multiple of whatever you specify, and it shows you what it's about to remove before it removes it.

It's part of the Y7Nodes pack, and the author's deadpan line in the docs - "You can always use a calculator if you prefer" - is the whole attitude of this node. It's a calculator you don't have to do math with, plus a preview.

How it works

Feed it an image and pick a multiple (default 16; 8, 16, and 32 are the common values for AI models). The node checks each dimension and crops down to the nearest multiple - 721 → 720 at multiple 16, that sort of thing. If a dimension is already aligned, it leaves it alone; it only crops what needs cropping. Note it crops down, so it's trimming pixels, not stretching.

The clever part is the control over where the crop happens, via two dropdowns:

  • h_crop - center, left, right, or none for the horizontal axis.
  • v_crop - center, top, bottom, or none for the vertical.

Setting an axis to none disables cropping on that axis entirely - handy when you only need one dimension fixed and don't want the other touched. And because cropping down always loses a few pixels, choosing center keeps the composition anchored rather than lopping a chunk off one edge.

Two edge-case behaviors worth knowing: with odd pixel differences, center rounds down (integer division), so a 1-pixel excess on a 721px width removes 1px from the right only - a maximum 1-pixel bias, which is standard and invisible. And the crop_preview output overlays a semi-transparent red region on the original showing exactly what will be trimmed, so you can inspect before committing.

Inputs and outputs

Inputs are the image plus the three settings above. Outputs:

  • crop_preview - the original image with the to-be-cropped area in red.
  • cropped_image - the result (or the original untouched, if nothing needed cropping).
  • info - a STRING status message with the dimension details and what was cropped. Useful for logging or for wiring into a text display.

The node also displays the cropped dimensions directly on the node after a run, so you can glance and confirm the output is aligned.

When you'd reach for it

Anywhere a downstream model demands divisible dimensions and your upstream isn't guaranteed to deliver them - after img2img at odd resolutions, after compositing, before a VAE decode that's picky about sizes, or before an upscaler that wants multiples of 64. It's a small insurance node: instead of discovering the divisibility failure at the end of the chain, you crop right after the operation that created the odd size.

Installing it

cd ComfyUI/custom_nodes
git clone https://github.com/yushan777/ComfyUI-Y7Nodes
cd ComfyUI-Y7Nodes
pip install -r requirements.txt

Restart ComfyUI, or install via ComfyUI Manager → search "Y7Nodes". It's pure torch image ops, so no extra heavy dependencies beyond the pack's standard requirements.

Verdict

Nothing exotic, but it's the rare utility that both fixes a real recurring problem and lets you see the fix before it happens. The none axis option is the sleeper feature - most crop-to-multiple tools force both dimensions, and being able to fix only the width is genuinely useful. If you've never hit a divisibility error, you can skip it; if you have, you'll keep it.

CategoryY7Nodes

Inputs (4)

NameTypeDefaultDescription
imageIMAGE
multipleINT161–1024Image dimensions must be multiples of this value
h_cropCOMBOcenterHorizontal crop position: where to keep content when width needs adjustment (none = no cropping)
v_cropCOMBOcenterVertical crop position: where to keep content when height needs adjustment (none = no cropping)

Outputs (3)

NameTypeDescription
crop_previewIMAGE
cropped_imageIMAGE
infoSTRING