Nodes/Duanyll Nodepack/Fill Bounding Box with Image
ComfyUI Node

Fill Bounding Box with Image

Paste Any Image Into a Detected Region, Automatically Resized

By Duanyll·Created about a year ago·Updated 4 months ago· 2
Fill Bounding Box with Image
  • src_image
  • bbox
  • fill_image
  • IMAGE

Compositing is usually "select, resize, paste" - three manual steps that break the moment the target changes size. FillBBoxWithImage collapses it to one node: give it a source image, a bounding box, and a fill image, and it stretches the fill image to exactly fit the box and drops it in place.

It's the compositing counterpart to BBoxCrop. Where BBoxCrop cuts a region out of an image, this one cuts in - replacing whatever currently sits inside the box with new content. Reach for it when you've detected a region (a face, a logo, a watermark zone) and want to overwrite it with something else at that exact spot, without hand-tweaking sizes.

How it works

Mechanically it's simple and predictable: the fill image is resized with Lanczos interpolation to the box's pixel dimensions, converted back to a tensor, and assigned into the source image's region. Coordinates are clipped to the source bounds, so a box hanging off the edge just fills the in-bounds portion.

One thing to note: it's a hard paste, not a blend. The fill image fully replaces the destination region - no alpha compositing, no opacity mixing, no feathering. If you want a soft edge or a semi-transparent result, that's downstream work. The node also takes a single bbox, not a list, so it's one box per node call.

Inputs and outputs

  • src_image - the image being modified.
  • bbox - the target region (the pack's BBOX type). Its coordinates decide the paste location and, after clipping, the final size.
  • fill_image - the content to paste; gets resized to the box, so aspect ratio is whatever the box dictates (expect stretching if box and fill have different shapes).

Output is the IMAGE with the region filled.

Where it fits

Typical chain: MaskToBBox or a detection node finds the region → FillBBoxWithImage drops replacement content in → maybe a mask-based blend afterward to sell the composite. It's a small, sharp tool - the kind that shines in automated batch pipelines where the box location changes every frame but the logic doesn't.

Installing it

It's part of Duanyll Nodepack:

cd ComfyUI/custom_nodes
git clone https://github.com/Duanyll/duanyll_nodepack

or install via ComfyUI Manager and restart. Pure tensor work - no models.

Gotchas

The stretch behavior is the one that catches people. A square fill image pasted into a tall thin box gets visibly distorted, because the resize is to fill, not to fit within. If you want letterboxed pasting instead of stretching, resize the fill yourself beforehand or pick a fill image whose aspect ratio matches the box. Also, since it modifies the source in place, don't expect the original region back afterward - that's the point, but it's worth saying before you wire the same image elsewhere expecting it unchanged.

Categoryduanyll/bbox

Inputs (3)

NameTypeDefaultDescription
src_imageIMAGE
bboxBBOX
fill_imageIMAGE

Outputs (1)

NameTypeDescription
IMAGEIMAGE