Nodes/ComfyUI-QING/图像裁剪丨百分比
ComfyUI Node

图像裁剪丨百分比

Crop by percentage — the fastest way to trim a composition

By sheengoa·Created about a year ago·Updated 19 days ago· 16
图像裁剪丨百分比
  • image
  • image
  • range_mask
  • crop_info
left0.0
top0.0
right0.0
bottom0.0

Sometimes you don't care about exact pixels - you just know the composition is a bit tight on the left, or you want a 4:5 crop out of a square, and you want it to work the same way on a 512px image or a 2048px one. That's what ImageCropByPercent is for: it shaves a percentage off each edge, and everything scales with the image.

It's part of the ComfyUI-QING pack (display name "图像裁剪丨百分比"), the same Chinese-authored utility collection that gives you pixel- and coordinate-based crop siblings. What distinguishes this one is that it's resolution-independent - a 10% trim is a 10% trim no matter what your source is.

How it works

Four required inputs - left, top, right, bottom - are FLOATs in percent (0–100, 0.1 steps). The node removes left% of the image width from the left edge, right% of the width from the right, top% of the height from the top, and bottom% of the height from the bottom. Left and right are relative to width; top and bottom to height - that asymmetry trips people up for about five seconds before it makes sense.

Internally it's straightforward: percent → pixel amounts, clamp to the image bounds, slice. No interpolation, no resampling, pure crop.

The outputs that matter

Like the whole QING crop family, this one returns three things:

  • image - the cropped tensor.
  • range_mask - a MASK at source resolution, white where the crop region is, black outside. Hand it to an inpaint or detailer and your crop becomes a region-aware operation instead of a one-way cut.
  • crop_info - a STRING reporting crop_box, the resulting size, the percent values used, and the source_size. crop_info is your friend when a crop looks wrong.

When to reach for it

Percentage crops shine for two jobs. First, aspect-ratio conversion: to turn a 1024×1024 square into roughly 4:5, trim 10% off the top and bottom - done, and it works on any resolution because it's all relative. Second, framing tweaks on batch jobs: if you're running 200 images through and want a consistent 5% breathing room around every subject, this is the node that stays correct across varied source sizes. A pixel-based trim would need per-image values; a percent trim doesn't.

The trade-off, naturally, is control. When you need exactly crop_box=(300,120)-(900,700) - say, a detector returned a precise face bounding box - you want the pixel or origin variants instead. This node is the "roughly there" tool, and that's a feature.

Installing

It ships with the whole pack, so install once, get all 79 nodes. ComfyUI Manager: search "ComfyUI-QING". Or:

cd ComfyUI/custom_nodes
git clone https://github.com/GAO-SHIQING/ComfyUI-QING
cd ComfyUI-QING
python install_dependencies.py   # or: pip install -r requirements.txt

Restart, and you're done. Dependencies are Pillow, opencv-python, scipy, scikit-image, cairosvg - plain pip packages, no model downloads. The author also includes a China mirror installer (--mirror --auto). Python ≥ 3.9 and a recent ComfyUI.

Gotchas

The one trap is real and easy to hit: if your left+right percentages exceed 100 (or top+bottom do), there's no image left - the node clamps everything to the bounds, detects a degenerate region, and returns the original image with a 裁剪失败 (crop failed) message in crop_info. No exception, no crash, just silently-uncropped output. If a percentage crop ever appears to do nothing, that's the first thing to check. Values are also hard-clamped to 0–100, so you can't go negative to "uncrop."

CategoryQING/图像处理

Inputs (5)

NameTypeDefaultDescription
imageIMAGE
leftFLOAT0.00–100左侧裁剪百分比数值(单位%)
topFLOAT0.00–100上侧裁剪百分比数值(单位%)
rightFLOAT0.00–100右侧裁剪百分比数值(单位%)
bottomFLOAT0.00–100下侧裁剪百分比数值(单位%)

Outputs (3)

NameTypeDescription
imageIMAGE
range_maskMASK
crop_infoSTRING