Nodes/comfyui-easyapi-nodes/CropTargetSizeImageByBbox
ComfyUI Node

CropTargetSizeImageByBbox

CropTargetSizeImageByBbox – ComfyUI Node

By lldacing·Created 3 years ago·Updated 8 months ago· 96
CropTargetSizeImageByBbox
  • image
  • bbox
  • crop_image
  • mask
  • crop_bbox
  • w
  • h
width512
height512
containfalse

What it is

This is CropImageByBbox's more opinionated sibling. Where the plain crop node cuts out exactly the bbox region plus a margin - so the output size varies with whatever the detector found - CropTargetSizeImageByBbox crops around the bbox's center to a fixed width and height you specify. If you need every output to be the same exact resolution (feeding a model with a strict input size, building a consistent dataset of face crops, anything where "512×512, always" matters more than "however big the detected box happened to be"), this is the node for that job.

The detected box just tells the node where the center of interest is; the actual crop dimensions come from width/height, not from the box itself. That's the core trade-off versus a plain bbox crop: you give up exact framing to gain exact, predictable output size.

Inputs and outputs

  • image (IMAGE, required).
  • bbox (BBOX, required) - corner-format [x, y, x1, y1], same convention as CropImageByBbox.
  • width (INT, default 512, range 1–16384) - target crop width.
  • height (INT, default 512, range 1–16384) - target crop height.
  • contain (BOOLEAN, default false) - governs how the target size relates to the detected box when they don't naturally match up (whether the crop is forced to contain the whole detected region rather than just being centered on it).

Outputs mirror the plain crop node: crop_image (IMAGE, now guaranteed to be exactly width×height), mask (MASK), crop_bbox (BBOX - the actual region taken from the source), w (INT), h (INT).

How it works

The node finds the center point of your bbox, then draws a width×height rectangle around that center rather than around the box's own edges. Near the edge of an image, the crop window obviously can't extend past the frame - expect the center to shift or the effective region to get clamped in that case rather than the node failing outright.

The contain flag is the setting worth experimenting with directly rather than guessing at: with it off, you get a crop of exactly your target size centered on the box, which may crop into or exclude part of a larger detected region if the box itself is bigger than your target dimensions. With it on, the node behaves more conservatively about keeping the whole detected box inside the output. If your target size is comfortably larger than typical detected boxes (a 512×512 crop around a face box that's usually 150×150), the difference will rarely matter in practice; it starts to matter when boxes and target size are closer in scale.

Installing it

Part of comfyui-easyapi-nodes. ComfyUI Manager: search "comfyui-easyapi-nodes", install, restart. Manual:

cd ComfyUI/custom_nodes
git clone https://github.com/lldacing/comfyui-easyapi-nodes.git
cd comfyui-easyapi-nodes
pip install -r requirements.txt

git pull in the folder to upgrade later. No special dependency for this node specifically, but installing requirements.txt keeps the rest of the pack functional too.

Common issues

"The crop is off-center or missing part of the face/object." If your target size is smaller than the detected bbox, something has to give - either the crop clips part of the box, or (with contain on) the effective crop grows past your requested size to fit the whole box. Toggle contain and compare; it's a one-checkbox test.

"I got a crop but it's noticeably shifted." You're likely near an image edge, where the fixed-size window can't stay centered without running off the frame and gets pulled back in. This is expected behavior for any center-based fixed-size crop, not specific to this node.

"I want the crop framed exactly on the detected box, not centered with padding." That's CropImageByBbox, not this one - reach for the plain crop node when you want output size to follow the box, and this one when you need every output locked to identical dimensions.

CategoryEasyApi/Bbox

Inputs (5)

NameTypeDefaultDescription
imageIMAGE
bboxBBOX参考区域坐标
widthINT5121–16384目标宽度
heightINT5121–16384目标高度
containBOOLEANfalse是否始终包含bbox完整区域

Outputs (5)

NameTypeDescription
crop_imageIMAGE
maskMASK
crop_bboxBBOX
wINT
hINT