Nodes/comfyui_my_img_util/Image Resize And Crop
ComfyUI Node

Image Resize And Crop

The cover-and-crop node

By sugarkwork·Created about a year ago·Updated 7 months ago· 2
Image Resize And Crop
  • image
  • image
width512
height512
method
h_aligncenter
v_aligncenter

The most common noob trap with ComfyUI resize nodes is ending up with squished faces. A naive resize to a fixed WxH ignores aspect ratio, and when your target is a different shape than your source, the image gets stretched - and diffusion models have strong opinions about stretched faces. Image Resize And Crop is the fix: it scales the image so it covers the target dimensions, like CSS object-fit: cover, then crops the overhang to hit the exact size. Nothing ever gets distorted, and you get to choose which edges are sacrificed.

How it works

The math is the cover algorithm. The node computes the scale needed to fit the width and the scale to fit the height, takes the larger of the two, and scales the whole image by that - so it always fills the target, with the excess hanging off one side. Then it crops to width × height, anchored by h_align and v_align, center by default.

Two code paths under the hood. lanczos is handled by Pillow, looping over each image in the batch - the crisp but slow path. Everything else (bicubic, bilinear, area, nearest) goes through PyTorch's F.interpolate, which is faster and batch-friendly. area is worth knowing about: it's averaging-based, which makes it a genuinely good choice for downscaling without shimmering aliasing.

The inputs and outputs that matter

  • image - input IMAGE.
  • width, height - target size in pixels, defaults 512, range 1–24576.
  • method - resampling method: lanczos (default), bicubic, bilinear, area, nearest.
  • h_align / v_align - where the crop lands: left/center/right and top/center/bottom.

Output: a single image, always exactly width × height.

The two you'll actually touch are width/height and the alignment. Center-crop is the safe default; if you're cropping a wide image to a tall one, decide whether you'd rather lose the left, the right, or a bit of both.

Installing it

It's part of the comfyui_my_img_util pack alongside four other image utilities. Install via ComfyUI Manager (search "comfyui_my_img_util") or:

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

Restart, and it's under "image". Dependencies: numpy, Pillow, opencv-python - the OpenCV one is pulled in for the pack's denoise node but imported at module level, so if it's missing, this node won't load either. No models.

Common issues

  • "Why did it cut off the top of the subject?" Because it's cover-and-crop, not fit-and-pad. When the source ratio differs from the target, the overhang has to go somewhere, and the default is to cut both sides equally. If the important content sits at one edge, set h_align/v_align to keep it. If you'd rather not crop at all - letterbox or pad - this is the wrong node; reach for a pad node (ImagePadForOutpaint or similar) instead.
  • Lanczos feels slow. It's the Pillow path, per image, and on a big batch it's the slowest option. For a fast normalization pass, bicubic or area is fine - nobody's A/B-ing the difference at 512px.
  • Small image, huge target. Upscaling is allowed, but a deterministic resize can't invent detail. If you want more pixels and more detail, resize to a sane size here and let an ESRGAN or SeedVR2 pass do the actual upscaling. This node is the "more pixels" half of that job, not the "invent detail" half.

Where you'd actually use it

Anywhere you need a uniform canvas: feeding a ControlNet preprocessor that wants a fixed size, normalizing a folder of mixed-ratio images for a training set, preparing frames for a video workflow, or generating a base image at 1024×1024 and cropping to a 16:9 composition afterwards. The aspect-ratio advice in the KB is basically "generate at a trained ratio, then crop" - this node is exactly that crop step, with the anchor control that keeps the crop where you want it.

Categoryimage

Inputs (6)

NameTypeDefaultDescription
imageIMAGE
widthINT5121–24576
heightINT5121–24576
methodCOMBO5 options: lanczos, bicubic, bilinear, area, nearest
h_alignCOMBOcenter3 options: left, center, right
v_alignCOMBOcenter3 options: top, center, bottom

Outputs (1)

NameTypeDescription
imageIMAGE