Nodes/CRT-Nodes/Quantize and Crop Image (CRT)
ComfyUI Node

Quantize and Crop Image (CRT)

Snap any image to a training-ready resolution

By PGCRT·Created 2 years ago·Updated a day ago· 132
Quantize and Crop Image (CRT)
  • image
  • image
  • width
  • height
max_side_length1024

Diffusion models are picky about input resolution in ways that make no sense at first. A perfectly good 1203×903 photo will trigger warnings, alias, or just underperform, while 1152×896 hums along. The reason: most modern checkpoints were trained on a fixed set of "buckets" - a handful of aspect-ratio-respecting sizes - and anything else gets awkwardly padded, cropped, or squashed before the VAE touches it. Quantize and Crop Image exists to do that snapping for you, on purpose, before anything else in the pipeline sees the pixels.

Give it an image and a max_side_length (default 1024, range 256–8192 in 64px steps), and it rescales the image to the nearest bucket that fits within your cap, keeping the aspect ratio, then rounds both dimensions down to a clean multiple of 64. It also outputs the final width and height as INTs, so downstream nodes don't have to guess what it decided.

How the bucket list works

Under the hood there's a fixed list of standard training resolutions - the usual suspects like 1024×1024, 1152×896, 1216×832, 1344×768, and their portrait/landscape mirrors - which is basically the bucket set SDXL and its descendants made canonical. The node picks the bucket whose aspect ratio is closest to your image's, then downscales that bucket to fit inside max_side_length if it exceeds it. If your image is 1536×1536 and your cap is 1024, you get 1024×1024; if it's 1920×1080, you land on a 16:9-ish bucket scaled to fit the cap.

The "crop" in the name is slightly generous - this node resizes and quantizes; it doesn't remove content. That's a feature: it's the "normalize before the sampler" step, not the "compose a shot" step.

Where you'd use it

  • Before img2img or edit passes where the model's behavior depends on being fed a canonical resolution.
  • Preprocessing a training dataset so every image lands on a bucket the trainer expects.
  • Feeding video frames to a VAE that wants 64-divisible dimensions - a 1280×720 frame becomes a clean bucket size instead of a borderline one.

Install

It's in CRT-Nodes:

cd ComfyUI/custom_nodes
git clone https://github.com/PGCRT/CRT-Nodes.git
pip install -r CRT-Nodes/requirements.txt

Restart ComfyUI (or use ComfyUI Manager and search CRT-Nodes). The node is under CRT/Image.

Troubleshooting

The main thing people trip on is expecting the output to preserve their exact image. It won't - that's the point. If your source is already at a canonical resolution, nothing changes; if it isn't, you'll see a slight scale or aspect shift. That's correct behavior.

Second: 64 is the quantization stride, so a max_side_length that isn't a multiple of 64 will effectively round. Set max_side_length to 1024 or 1152 rather than 1000 or 1100 to avoid surprises, and remember the node reports the real final size through its width/height outputs - trust those, not the slider, when wiring downstream.

CategoryCRT/Image

Inputs (2)

NameTypeDefaultDescription
imageIMAGE
max_side_lengthINT1024256–8192The absolute maximum size (in pixels) for either the width or height of the final image.

Outputs (3)

NameTypeDescription
imageIMAGE
widthINT
heightINT