图像裁剪丨百分比
Crop by percentage — the fastest way to trim a composition
- image
- image
- range_mask
- crop_info
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 reportingcrop_box, the resultingsize, the percent values used, and thesource_size.crop_infois 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."
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| left | FLOAT | 0.00–100 | 左侧裁剪百分比数值(单位%) |
| top | FLOAT | 0.00–100 | 上侧裁剪百分比数值(单位%) |
| right | FLOAT | 0.00–100 | 右侧裁剪百分比数值(单位%) |
| bottom | FLOAT | 0.00–100 | 下侧裁剪百分比数值(单位%) |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| range_mask | MASK | — |
| crop_info | STRING | — |