Nodes/ComfyUI-CustomNodeKit/图像批次缩放
ComfyUI Node

图像批次缩放

Get every frame to 512x512 without murdering the aspect ratio

By user2318·Created 4 months ago·Updated about a month ago· 56
图像批次缩放
  • images
  • images
width512
height512
crop_modedisabled

Video models are picky about resolution, and your input frames are not. WanAnimate wants everything at a matching size, reference batches need to line up, and somewhere between your folder of renders and the encoder there's always a frame that's the wrong shape. Image Batch Resize is the pack's answer: scale an entire batch to an exact width and height, using Pillow's LANCZOS, and - this is the part worth caring about - do it without stretching the image into a lie.

The trap it saves you from is the classic resize(512, 512) that squeezes a 16:9 frame into a square. crop_mode is the dial:

  • disabled (default) - direct stretch to width×height. Fast, and looks bad whenever your source aspect ratio differs from the target.
  • center / top / bottom / left / right - scale-to-cover first (so nothing is squeezed), then crop the overflow from the chosen direction. This is how you get a true 512×512 crop out of a 1920×1080 frame without the person looking like a funhouse mirror.

The README even has the worked example: a 1920×1080 source to 512×512, center scales it to 911×512 and crops 199px off each side. That's the math you'd rather let the node do.

What you set

  • width / height - target size in pixels, default 512×512.
  • crop_mode - stretch vs. scale-and-crop. If your subject is centered, center is the safe default; if it's a standing person, top bias keeps their head.
  • images - the batch in, the resized batch out as images. Invalid input (None, empty) returns None rather than erroring, consistent with the rest of the pack.

When you'd reach for it

This is a glue node, and it shows up everywhere in this pack's workflows: normalizing reference images before a WanAnimate batch, squaring up pose drawings, getting mixed-resolution folder loaders onto one canvas before ImageBatchConcatNode. If you're stitching together a batch for a video model, resize before you concat - mixing resolutions and then concatting is how you get shape errors three nodes downstream.

Install

Ships in user2318/ComfyUI-CustomNodeKit. ComfyUI Manager: search "CustomNodeKit". Or:

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

then restart. No models, just Pillow, which ComfyUI always has.

The gotcha

crop_mode = disabled and "it came out distorted" are the same sentence. If your output faces look squashed, you're in stretch mode - switch to a crop mode. The flip side: crop modes discard pixels, so a center crop of a wide shot can chop a person's shoulders. The node does exactly what it says, no hidden content-awareness. And remember the order in a batch pipeline: resize before concat, and if you're upscaling a batch for video, do it before you need it to match the VAE's expectations - this node just makes the pixels a certain size, it doesn't make them "correct."

Categoryimage

Inputs (4)

NameTypeDefaultDescription
widthINT512目标宽度(像素)。Target width (pixels).
heightINT512目标高度(像素)。Target height (pixels).
crop_modeCOMBOdisabled裁剪模式。disabled:直接拉伸不保持比例;center/top/bottom/left/right:先等比缩放覆盖目标再按方向裁剪。Crop mode: disabled — stretch directly without aspect ratio; center/top/bottom/left/right — scale to cover then crop from the specified direction.
imagesoptIMAGE输入图像批次。无输入或输入无效时输出None。Input image batch. Outputs None when no input or invalid input.

Outputs (1)

NameTypeDescription
imagesIMAGE