Nodes/SDVN_Comfy_node/βœ‚οΈ Crop By Ratio
ComfyUI Node

βœ‚οΈ Crop By Ratio

Crop to an aspect ratio without distorting anything

By StableDiffusionVNΒ·Created 2 years agoΒ·Updated about a month agoΒ· 118
βœ‚οΈ Crop By Ratio
  • image
  • cropped_image
β—„ratioβ–Ύβ–Ί
β—„positionβ–Ύβ–Ί

You've got an image at some awkward aspect ratio and you need it at a clean one - 1:1 for a thumbnail, 16:9 for a banner, 2:3 to match a model's native shape - without squishing it. Crop By Ratio does exactly that: it cuts the image down to the target ratio and lets you choose which part to keep. No resizing, no stretching, no distortion. It just trims off the excess to hit the shape you asked for.

The reason to crop rather than resize-to-fit is simple: resizing to a new ratio warps the picture. Cropping preserves the pixels' true proportions and throws away the edges you don't need. This is the "keep it looking right" way to change shape.

How it works

You give it a target ratio and a position. The node figures out the largest rectangle of that aspect ratio that fits inside your image, then places that crop window according to the anchor you picked - one of nine positions from top-left through center-mid to bottom-right. Whatever falls outside the window is cropped away. Because it only cuts, nothing gets scaled or stretched.

The inputs and outputs that matter

  • image - the picture to crop.
  • ratio - the target aspect ratio: 1:1, 4:5, 5:4, 2:3, 3:2, 16:9, 9:16, 1:2, 2:1, or None to pass through.
  • position - which region survives the crop, on a 3Γ—3 grid (top-left, center-mid, bottom-right, and the six in between). This is how you keep the subject in frame.

The output is cropped_image - feed it into an img2img encode, a ControlNet reference, an upscale, or a Save.

How to install it

Comes with the SDVN pack. ComfyUI Manager, search SDVN_Comfy_node; or:

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

from the ComfyUI root, then restart. No models, no dependencies.

Common issues & troubleshooting

It cropped off my subject. That's the position anchor. If your subject sits at the top of a portrait and you cropped to a wide ratio with center-mid, you may have lost their head. Set the anchor toward where the important content lives (top-mid for a standing figure, say).

It didn't change the pixel dimensions I wanted. This node sets the ratio, not an exact width and height - it hands you a correctly-proportioned crop at whatever size that works out to. If you need a specific resolution, follow it with a resize/upscale node.

Ratio None does nothing. Leaving ratio on None passes the image straight through. Pick an actual ratio for it to crop.

You need to keep the whole image. Cropping loses edges by definition. If you'd rather pad the image out to a ratio (letterbox it) instead of cutting, that's a different tool - the pack's Fill Background or an Empty Latent Ratio composite, not this node.

CategoryπŸ“‚ SDVN/🏞️ Image

Inputs (3)

NameTypeDefaultDescription
imageIMAGEβ€”
ratioCOMBO10 options: None, 1:1, 4:5, 5:4, 2:3, 3:2, +4
positionCOMBO9 options: top-left, top-mid, top-right, center-left, center-mid, center-right, +3

Outputs (1)

NameTypeDescription
cropped_imageIMAGEβ€”