Nodes/ComfyUI_KimNodes/🍒Percentage_Cropper✀百分比裁剪
ComfyUI Node

🍒Percentage_Cropper✀百分比裁剪

Crop by percent, not pixels — the right tool when image sizes vary

By wjl0313·Created 2 years ago·Updated 12 months ago· 54
🍒Percentage_Cropper✀百分比裁剪
  • image
  • IMAGE
horizontal_percent10.0
vertical_percent10.0

Most ComfyUI crops are pixel-based: you tell the node "cut 64px off every side" and it does exactly that. Percentage_Cropper is the other approach - you tell it "cut 10% off each side," and it works no matter how big or small the image is.

That difference matters the moment your input sizes vary. Say you're trimming letterbox bars or dead space off a batch of generated images that came out at different resolutions. A fixed-pixel crop is wrong for most of them; a percentage crop scales with each image. Same deal if you're reframing by a rule of thumb ("the subject lives in the middle 80%") rather than by measured pixels.

The mechanism. It's a centered crop, nothing clever. horizontal_percent is a percentage of the image width split in half and removed from both sides; vertical_percent does the same for height. So the defaults (10 and 10) shave 5% off the left, 5% off the right, 5% off the top, 5% off the bottom - you keep the center 90%. The author's own docstring calls it "crop inward by percentage of width and height," and that's precisely what the math does.

Inputs. Three, and only one of them will ever need touching:

  • image - what you're cropping.
  • horizontal_percent - FLOAT, default 10, range 0–100, step 0.1.
  • vertical_percent - FLOAT, default 10, same range.

Output. A single cropped IMAGE, same batch count as the input. There's no mask, no bounding box, no metadata - this is a blunt instrument on purpose.

Where it fits. Use it for trimming uniform borders (white margins around an upscaled render, prompt-injection letterboxing, padding from a square-pad step) where the border is roughly proportional to the image. Don't use it when you need precision - the pack's own Transparent_Area_Cropper does mask-aware trimming, and BoundingBox_Cropper handles "crop exactly this region." Percentage_Cropper is the "just shave a chunk off" node.

Gotchas. A couple of things to keep in mind. First, 100 in a field crops the whole image down to nothing - the code happily computes H - H/2 - H/2 and you get a sliver. Second, there's no aspect-ratio logic: setting equal horizontal and vertical percentages keeps proportions only if the source is already square-ish, and it'll happily distort your framing (not the image, just the crop window). Third, fractional results are floor-int'd, so a 1px difference on odd sizes is normal.

Install. It's part of KimNodes (wjl0313's 🍒 toolbox, registered on the Comfy registry). Via Manager, search "ComfyUI_KimNodes"; or manually:

cd ComfyUI/custom_nodes
git clone https://github.com/wjl0313/ComfyUI_KimNodes

Restart ComfyUI after installing. Like the other crop tools in this pack, it's pure tensor slicing - no models, no downloads, no heavy dependencies.

Troubleshooting. If the crop comes out unexpectedly aggressive, remember the percentage is split across both sides - "10" is not "10% off total," it's "10% off total spread over two edges." If nothing changes at all, check that you're not feeding it through a node that already cropped; and if your input is a grayscale or RGBA tensor, it crops fine but outputs stay in that mode, so an RGBA in gives an RGBA out. That's usually what you want when you're about to composite.

Category🍒 Kim-Nodes/✂ Crop | 裁剪工具

Inputs (3)

NameTypeDefaultDescription
imageIMAGE
horizontal_percentFLOAT10.00–100
vertical_percentFLOAT10.00–100

Outputs (1)

NameTypeDescription
IMAGEIMAGE