PD:Image Crop_ratio
Image Crop_ratio — crop a fixed fraction of the frame, and take the mask with you
- image
- mask
- cropped_image
- cropped_mask
Sometimes you don't want to crop to a size, you want to crop by a proportion - "drop the bottom 10% of this frame," "keep the left third." PD:Image Crop_ratio is that node: it shaves a strip off one edge of the image, where the strip width is defined as a ratio, and - this is the part the pack gets right - it crops any connected mask in perfect lockstep. If your crop is going to feed an inpainting or compositing step, that mask alignment is the difference between "it works" and "the seam is wrong."
How it works
The math is embarrassingly simple, which is why it's reliable: on the x-axis, seg_w = width * ratio_a / ratio_b. If ratio_a = 1 and ratio_b = 2, you keep half the width; ratio_a = 1, ratio_b = 4 keeps a quarter. direction decides which edge gets shaved - left and right work on the x-axis, top and bottom on the y-axis - and axis picks whether ratio_a/ratio_b applies to width or height. The mask (if connected) gets the identical slice, so the crop and the mask never drift.
The inputs that matter
- image (
IMAGE) - the source. - ratio_a (
INT, default 1) and ratio_b (INT, default 100) - the fraction you keep. Read it as "ratio_a out of ratio_b." - axis -
xory(defaultx). - direction -
left/right/top/bottom(defaultleft), which edge to crop from. - mask (
MASK, optional) - cropped alongside.
Outputs: cropped_image (IMAGE) and cropped_mask (MASK). If no mask is connected, cropped_mask comes back None, so don't wire it into a mask-only input expecting an all-white region - for that, use the location-crop V2 which mints a mask for you.
The trap hiding in the defaults
ratio_a defaults to 1 and ratio_b to 100. That combination crops a 1%-wide sliver off the edge of your image. If you drop the node in and hit run, you'll get a nearly-invisible strip and spend ten minutes wondering if the node is broken. It isn't - you just forgot the defaults mean "keep 1%." Set ratio_a = ratio_b to keep everything, or think in "keep this much out of that much" terms: 1:2, 3:4, 9:16. This is the single most likely thing to confuse you, and it's worth checking before you blame the pack.
A real use
Frame-crop a watermark band: run the image with axis=y, direction=bottom, ratio_a=9, ratio_b=10 to drop the bottom tenth where the watermark lives, and feed the resulting cropped_mask into an inpaint if the region needs cleanup. Because the mask came along, any inpaint region stays perfectly aligned with the pixels.
Install
ComfyUI Manager: search PDuse (repo 7BEII/Comfyui_PDuse), install, restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/7BEII/Comfyui_PDuse
cd Comfyui_PDuse
pip install -r requirements.txt
Restart and look for PD:Image Crop_ratio under PDuse/Image. Keep it for the proportional crops; its sibling PD:Image Crop_custom handles the pixel-sized version of the same idea.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| ratio_a | INT | 11–1000 | — |
| ratio_b | INT | 1001–1000 | — |
| axis | COMBO | x | 2 options: x, y |
| direction | COMBO | left | 4 options: left, right, top, bottom |
| maskopt | MASK | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| cropped_image | IMAGE | — |
| cropped_mask | MASK | — |