Nodes/ComfyUI-ZML-Image/ZML_限制图像比例
ComfyUI Node

ZML_限制图像比例

Pad, crop, or stretch to a fixed ratio

By zml-w·Created about a year ago·Updated 2 months ago· 218
ZML_限制图像比例
  • 图像
  • 处理后图像
目标比例1:1
模式

ZML_LimitImageAspect (ZML_限制图像比例, "limit image aspect ratio") is the "make this image conform" node: pick a target ratio - 1:1, 16:9, 9:16, and eight more - pick how you want to get there, and it normalizes the image without asking questions. If you've ever tried to feed a batch of mixed-ratio images into something that needs uniformity, you know the exact pain this solves.

It's from ComfyUI-ZML-Image, zml-w's 160+ node pack (added in a September 2025 update), and it lives in the plain image subcategory.

How it works

The node takes your image and a 目标比例 (target ratio) from eleven presets, then reshapes it to match using one of four 模式 (modes):

  • 填充白 (fill white) / 填充黑 (fill black) - letterbox: the image keeps its pixels and empty space is padded with white or black bars to reach the ratio. Nothing is lost.
  • 裁剪 (crop) - the image is cropped to the ratio, so the outer edges go away. Nothing is padded.
  • 拉伸 (stretch) - the image is squashed or stretched to fit the ratio exactly. Everything is kept, nothing is lost, and yes, it can distort.

Same four options you'd get in a video editor's "fit" dropdown, minus the subtlety. The output is a single 处理后图像 (processed image), ready for whatever demanded uniform aspect.

What it's actually for

Batch hygiene, mostly. When you're compositing a grid, feeding a video pipeline, or running a detailer across images that must share a canvas, mismatched ratios are the silent killer - they either get auto-cropped by the downstream node (losing your framing) or error out. Run a normalization pass first and the rest of the pipeline stops caring.

The pack's own README suggests the natural follow-up: after padding, run its crop-pure-background node to strip the white/black bars back off when you only needed the ratio internally. Pad to ratio for the pipeline, crop the padding for the output.

Installing it

Pack install:

cd ComfyUI/custom_nodes
git clone https://github.com/zml-w/ComfyUI-ZML-Image

restart ComfyUI, or ComfyUI Manager → search "ComfyUI-ZML-Image". Pure PIL under the hood - no OpenCV dependency for this one, no models.

Where people get caught

Two things. First, "fill white" vs "crop" are genuinely different data-loss trade-offs: padding preserves every pixel but adds bars, cropping discards pixels. Pick deliberately - most people want crop for content normalization (a 4:3 photo forced to 16:9) and pad only when the downstream explicitly demands a full frame. Second, stretch is the one that bites: it hits the target ratio exactly but can visibly squish faces and text. If the source is close to the target, the distortion is minor; if it's far off, it's a warped mess. When in doubt, crop.

And one honest note: there's no "custom ratio" input here - the eleven presets are the whole menu. If you need 3:1 or something unusual, you'll want a resize/crop combo instead of this node.

Categoryimage/ZML_图像/图像

Inputs (3)

NameTypeDefaultDescription
图像IMAGE
目标比例COMBO1:111 options: 1:1, 16:9, 9:16, 3:2, 2:3, 4:3, +5
模式COMBO4 options: 填充白, 填充黑, 裁剪, 拉伸

Outputs (1)

NameTypeDescription
处理后图像IMAGE