Nodes/ComfyUI-ZML-Image/ZML_图像裁剪
ComfyUI Node

ZML_图像裁剪

Crop with numbers, not guesswork

By zml-w·Created about a year ago·Updated 2 months ago· 218
ZML_图像裁剪
  • 图像
  • 裁剪后图像
  • 裁剪掉的图像
  • X坐标
  • Y坐标
  • 裁剪宽度
  • 裁剪高度
裁剪比例禁用
裁剪方向居中
宽度512
高度512
X偏移0
Y偏移0

There are two ways to crop in ComfyUI: point-and-click visual cropping, and math. ZML_ImageCrop is the math one, and it's quietly better than it looks because it doesn't just give you the cropped image - it hands you the exact crop rectangle as numbers, plus the region you cut away, so you can stitch things back together or feed coordinates into other nodes.

It's from ComfyUI-ZML-Image, the big Chinese utility pack by zml-w (160+ nodes, all ZML_-prefixed, living under an "图像" category). This one sits in the plain image subcategory and is about as dependency-light as the pack gets - pure tensor slicing, no OpenCV, no models.

How it works

The node takes a center-anchored crop and lets you move it with numbers. Two modes:

  • 裁剪比例 (aspect ratio) mode - pick a preset (1:1, 16:9, 9:16, 4:3, 3:4, 3:2, 2:3, 21:9) and a 裁剪方向 (center / top / bottom / left / right). The node keeps the larger dimension and crops the other side down to match the ratio, anchored wherever you said.
  • Custom mode - 裁剪比例 set to "禁用" (disabled), and you type the 宽度 (width) and 高度 (height) directly, then nudge the window with X偏移 / Y偏移 (positive X is right, positive Y is down). This is your "make it exactly 832×1216" tool.

The outputs that matter

Six outputs, and most of them are the point:

  • 裁剪后图像 - the cropped image you actually want.
  • 裁剪掉的图像 - the original with the crop region blacked out. This is the one people miss: instead of a removed strip, you get the original image with a black hole where the crop was. Composite the two back together and you've reversed the crop losslessly.
  • X坐标 / Y坐标 / 裁剪宽度 / 裁剪高度 - the crop rectangle as integers. Wire these into any node that wants a bounding box, or use them to place the crop back onto another canvas.

Installing it

Same as every node in the pack - one install, all siblings come with it:

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

then restart ComfyUI. Easier: ComfyUI Manager → search "ComfyUI-ZML-Image" → install. It pulls a heavy requirements list (OpenCV, scipy, ultralytics) for the pack's other nodes, but this one itself needs nothing beyond core. No models to download for the crop.

Where people get caught

The 裁剪掉的图像 output is a trap if you expected the removed strip. It's not - it's the "outside" image with the hole cut in it. Read it as a compositing aid, not a standalone piece.

Also note it's a strict crop: it slices pixels, it doesn't resize. If you crop a 1024×1024 down to 16:9, you get ~1024×576, not a resized 1024×576-scaled-to-fit. Pair it with an upscale or resize node if you need a fixed output size.

When you'd actually reach for it

The coordinate outputs make this the crop to reach for when you're building multi-stage workflows - crop a region, remember where it was, inpaint or upscale it, paste it back. If you just want to eyeball a crop, the pack's visual crop node (button-driven UI) is the friendlier sibling; this one is for the moments you want the numbers.

Categoryimage/ZML_图像/图像

Inputs (7)

NameTypeDefaultDescription
图像IMAGE输入要裁剪的图像
裁剪比例COMBO禁用选择裁剪比例,选择'禁用'可使用自定义宽高
裁剪方向COMBO居中裁剪比例模式下的裁剪方向
宽度INT5121–16384禁用比例模式时的裁剪宽度
高度INT5121–16384禁用比例模式时的裁剪高度
X偏移INT0-16384–16384禁用比例模式时的水平偏移像素(正数向右,负数向左)
Y偏移INT0-16384–16384禁用比例模式时的垂直偏移像素(正数向下,负数向上)

Outputs (6)

NameTypeDescription
裁剪后图像IMAGE
裁剪掉的图像IMAGE
X坐标INT
Y坐标INT
裁剪宽度INT
裁剪高度INT