ImageCropByRatio
ImageCropByRatio — crop to an aspect ratio without resizing anything
- image
- IMAGE
- width
- height
ImageCropByRatio crops an image to a target aspect ratio and, crucially, doesn't resize it - it just trims the overflow. You feed it a width_ratio and height_ratio, it keeps the dimension that fits and chops the other side down so the remaining pixels match that ratio. Out come the cropped IMAGE plus the cropped width and height as INTs. That's the whole node, and it's one of those small things you reach for more than you'd expect once you know it exists.
Why crop instead of just resizing? Resizing distorts or loses detail; cropping throws away the least important pixels and keeps everything else at native resolution. If you're about to run an image through a latent model with a fixed aspect (SD1.5's 512x512, SDXL's 768x768-ish, or a video model's aspect box), cropping first means the model isn't squeezing your composition. The pack it lives in is video-generation-focused, so the intended job is prepping stills and frames for video latents - but it works for any aspect-matching chore.
How it works. The math is straightforward: it compares your image's aspect ratio (width/height) against the target ratio, then trims the excess on the wider axis. The position dropdown decides which part you keep:
center- keep the middle (default-ish)top,bottom- keep the top or bottom when trimming heightleft,right- keep the left or right when trimming width
The crop is done by plain tensor slicing, so it's fast and lossless - no resampling, no interpolation involved.
Inputs and outputs. image (IMAGE), width_ratio (INT, default 1), height_ratio (INT, default 1), position (enum: top/right/bottom/left/center). Outputs: IMAGE plus width and height INTs - which are the cropped pixel dimensions, not your ratio numbers, so you can wire them straight into an EmptyLatentImage without recomputing.
Gotcha worth knowing. The ratio ints are a pure ratio, not a target resolution. width_ratio=16, height_ratio=9 gives you a 16:9 crop at whatever native size fits - don't expect it to be 1920x1080. If you want the crop and an exact pixel output size, that's the sibling node ImageCropByRatioAndResize, which crops then resizes to width_ratio_size × height_ratio_size. If your source is already close to the target ratio, the crop is tiny; if it's way off, you're cutting a lot of composition, so pick the position deliberately.
Install. It's part of komojini-comfyui-nodes:
ComfyUI Manager → search "komojini-comfyui-nodes" → Install → restart
or cd ComfyUI/custom_nodes && git clone https://github.com/komojini/komojini-comfyui-nodes. No models, no heavy deps. It's also one of the pack's few genuinely standalone utilities - if you never touch the video stuff, this single node still justifies the install.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| width_ratio | INT | 11–8192 | — |
| height_ratio | INT | 11–8192 | — |
| position | COMBO | 5 options: top, right, bottom, left, center |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |
| width | INT | — |
| height | INT | — |