ComfyUI Node

Cropimg

Change an image's aspect ratio without shrinking the image you keep

By MakkiShizu·Created 2 years ago·Updated about a year ago· 4
Cropimg
  • image
  • image
  • width
  • height
  • count
  • channels
upscale_methodbicubic
crop_methodscenter
width_ratio1.000
height_ratio1.000

The other two nodes in this pack snap sizes to a target number. Cropimg does something subtler: it changes an image's aspect ratio while keeping the total pixel count roughly constant. A 1024×1024 square becomes a ~1365×768 landscape - about the same megapixels, different shape. It rearranges the budget, it doesn't shrink it.

When do you actually want that? Two common cases. You loaded or generated a portrait and the canvas needs to be landscape (or the reverse), and you don't want to pay the resolution cost of a straight upscale or lose detail to a straight downscale - you want the same amount of image, just reshaped. Or you're prepping reference images for ControlNet and want the conditioning at the same megapixel count as the generation canvas without a quality-changing resize. Cropimg keeps the detail budget where it was.

How it works

It computes the aspect you asked for (width_ratio / height_ratio), anchors one side, and narrows the other: if the source is wider than the target ratio it keeps the height and trims the width, otherwise the reverse. Then it scales the result so new_width × new_height ≈ original_width × original_height. The actual resampling runs through comfy.utils.common_upscale - core ComfyUI, the same helper the stock ImageScale node uses.

The default crop_methods = center is the sane setting: it trims a center strip to the target ratio, then scales it up to keep total pixels - no distortion. Switch to disabled and it stretches the whole frame to the ratio instead (nothing trimmed, everything slightly squashed).

Worked example: 1024×1024 in, width_ratio = 16, height_ratio = 9 → center strip becomes 1365×768, ~1.05MP. Same budget as the input, 16:9 shape out.

Inputs that matter

  • width_ratio / height_ratio - the aspect you want as a pair: 16 and 9 for 16:9, 4 and 3 for 4:3, 1 and 1 for square.
  • crop_methods - center (default, trims edges evenly) or disabled (stretches).
  • upscale_method - nearest-exact, bilinear, area, bicubic (default), or lanczos; nearest-exact for pixel art.

Outputs

image plus width, height, count, and channels - the batch and channel counts pass through unchanged, same as Reimgsize.

Where people get burned

There's no GCD snapping in this node, so outputs land on whatever numbers the math produces - 1365×768 is fine for most models, but Flux's "divisible by 64" habit will frown at it. If you care, chain the output into Reimgsize (same pack) with GCD 64 to clean it up. And remember the center crop is where your subject's edges go: if you framed something near the frame edge, that's exactly what gets trimmed. Set crop_methods to disabled if you'd rather stretch the whole frame than lose that sliver. It also resamples (interpolates), so it's not lossless - you're trading a crop for a gentle rescale, not inventing new pixels.

Install

Same pack as the others - this one's a member of MakkiShizu/comfyui_reimgsize, a three-node, zero-dependency pack. Manager search "comfyui_reimgsize", or:

cd ComfyUI/custom_nodes
git clone https://github.com/MakkiShizu/comfyui_reimgsize.git

Restart ComfyUI and you'll find Cropimg under the comfyui_reimgsize category. No models to download, nothing to configure.

Categorycomfyui_reimgsize

Inputs (5)

NameTypeDefaultDescription
imageIMAGE
upscale_methodCOMBObicubic5 options: nearest-exact, bilinear, area, bicubic, lanczos
crop_methodsCOMBOcenter2 options: disabled, center
width_ratioFLOAT1.0000.001–64
height_ratioFLOAT1.0000.001–64

Outputs (5)

NameTypeDescription
imageIMAGE
widthINT
heightINT
countINT
channelsINT