ComfyUI Node

BoxCropImage PM

The boring box cropper that ties this pack together

By THtianhao·Created 3 years ago·Updated 2 years ago· 201
BoxCropImage PM
  • image
  • box
  • crop_image

BoxCropImage PM does one thing: crops an image to a bounding box. No resizing, no padding, no mask - you hand it an image and a BOX, and it hands back the pixels inside that box. It's the least glamorous node in the Portrait-Maker pack and that's exactly why it's useful.

The mechanism is a plain tensor slice: image[:, y1:y3, x1:x2, :] against the box's four values. There's nothing clever under the hood, which means it's fast, predictable, and easy to reason about.

Two inputs, one output:

  • image - what you want to cut.
  • box - a BOX (four numbers, x1, y1, x2, y2).

Output is crop_image.

Where it earns its place is when you have a box computed on one image and want to apply the same region to another. That's the pack's whole design: RetinaFace emits a crop_box, and nodes like ExpandMaskBox and ReplaceBoxImg pass those boxes around so that everything stays in the same pixel space. So the classic move is - run RetinaFace to find the face and get its crop_box, then use BoxCropImage to cut the same region out of a different image (say, the fused output of FaceFusion) without re-running detection. Since RetinaFace doesn't resize your input before detecting, the box coordinates line up with the original image exactly, and this node preserves that by doing zero scaling of its own.

Two things to watch. First, the box has to be valid for the image you feed it - if the box extends past the image edge you'll get an empty or edge-clipped crop, and unlike a resize-based crop there's no clamping. Second, there's no "get a box from nowhere" option here; if you don't have a box to feed it, you need to produce one with another node (RetinaFace's crop_box or ExpandMaskBox), or you're stuck. That's the only friction, and it's minor.

Install is the pack-wide story: ComfyUI Manager or git clone https://github.com/THtianhao/ComfyUI-Portrait-Maker into custom_nodes, restart, and let the startup download run. This particular node needs none of the heavy models - it's pure tensor math - so it works even if you only want the utility nodes and never touch the face models. That's honestly a decent reason to keep the pack around: the crop/box/mask helpers are the sort of plumbing that's handy even when the 2024-era face models have aged past what you need.

Categoryprotrait/other

Inputs (2)

NameTypeDefaultDescription
imageIMAGE
boxBOX

Outputs (1)

NameTypeDescription
crop_imageIMAGE