Nodes/ComfyUI-TinyBee/Change Rect Aspect
ComfyUI Node

Change Rect Aspect

Reshape a detection box to any aspect ratio without losing the subject

By TinyBeeman·Created about a year ago·Updated 10 days ago· 1
Change Rect Aspect
  • image
  • tinyrect
  • tinyrect
  • exceeded_bounds
  • shrunk
aspect_ratio1.00
center_wfalse
center_hfalse
limitsenforce image bounds

Detectors return whatever shape the detected thing happened to be; samplers and upscalers want a shape you chose. A face box might come back near-square when you need a portrait crop, or tall and skinny when the model you're feeding wants 4:3. Change Rect Aspect takes a TINYRECT and a target aspect ratio and rebuilds the box to match - growing width or height as needed, with the ability to respect the image's actual bounds so the reshaped box doesn't float off the canvas.

The math is straightforward aspect-ratio arithmetic: if the box is too wide for the target, it grows the height; too tall, it grows the width. The interesting part is anchoring - where the growth happens - and what happens when there's no room to grow.

The inputs that matter

  • image and tinyrect - the canvas and box to reshape. The image matters because of the limits mode below.
  • aspect_ratio - target width/height, default 1.0. 1.5 is 3:2, 0.75 is 3:4 portrait.
  • center_w, center_h - the anchor control. Off (default) means "Grow Right" / "Grow Bottom" - the box keeps its left or top edge fixed and grows in one direction. On means centered growth on that axis, which keeps the subject roughly in the middle. For portrait crops you usually want centering; for region refinement against an image edge you want the anchored mode.
  • limits - the mode enum with three choices:
    • ignore image bounds - just grow to the target, even if the box hangs off the image.
    • enforce image bounds (default) - grow as far as the image allows, then shrink the other axis to hit the exact aspect ratio. This is the one that keeps the box valid for cropping but can tighten the region - hence the shrunk output flag.
    • best fit - try to stay in bounds, and if it genuinely can't, fall back to exceeding them rather than shrinking.

The outputs that matter

tinyrect is the reshaped box. exceeded_bounds tells you the box pokes outside the image (always false in enforce mode - that's the whole point of enforce). shrunk is the one to watch: true means enforce mode had to compress the other axis to preserve the ratio, so the region got smaller than the original detection. If your detailer suddenly seems to be cropping tighter than before, this flag is why.

Install and gotchas

Standard TinyBee install:

cd ComfyUI/custom_nodes
git clone https://github.com/TinyBeeman/ComfyUI-TinyBee

or ComfyUI Manager → "ComfyUI-TinyBee" → restart. No models, no dependencies beyond the pack's light requirements.txt. The frequent surprise is shrunk in enforce mode - people see a smaller crop and assume a bug, but it's the correct trade for "must be this ratio, must not leave the image." If you'd rather grow than shrink, best fit (or checking exceeded_bounds and growing the canvas with Crop/Grow Image to Bounds) is your alternative. It's in 🐝TinyBee/Rectangles with the rest of the geometry family.

Category🐝TinyBee/Rectangles

Inputs (6)

NameTypeDefaultDescription
imageIMAGE
tinyrectTINYRECT
aspect_ratioFLOAT1.000.01–100
center_wBOOLEANfalse
center_hBOOLEANfalse
limitsCOMBOenforce image bounds3 options: ignore image bounds, enforce image bounds, best fit

Outputs (3)

NameTypeDescription
tinyrectTINYRECT
exceeded_boundsBOOLEAN
shrunkBOOLEAN