Area Based Scale
Scale a layer so its area matches a target — aspect kept, cap included
- width_a
- height_a
- width_b
- height_b
- width
- height
- scale_ratio
Most scaling math in ComfyUI works on one dimension: "make this 1024 wide" or "double the height." This node works on area. You give it group A's dimensions (the thing you want to scale) and group B's dimensions (the reference - think of it as your canvas), and it computes the width and height that keep A's aspect ratio while making A's total area equal to B's area times a ratio you set. Set ratio to 0.5 and group A comes out occupying half the area of group B - not half the width, half the pixels. It's a different kind of sizing than you're used to, and it's exactly what you want when you care about visual weight rather than a specific pixel width.
Where it shines is smart placement pipelines: you have a subject that should fill a certain fraction of a canvas, and you don't want to hand-compute dimensions every time the canvas changes. Feed it live dimensions (it accepts numbers from anywhere - Get Image Size, Get Mask Size, or plain values), and it recomputes on every run.
How it works
The math: output area = area of B × ratio, with A's aspect ratio preserved. So if A is a wide rectangle and B is a tall canvas, the result keeps A's proportions but occupies the requested slice of B's total area.
The differentiator from the pack's other scaling nodes is the cap:
- cap_threshold - a fraction of B's dimensions that acts as an upper ceiling. Default 0.7.
- enable_cap - the switch for that ceiling, default on.
With both active, if the computed size would exceed B's dimensions × cap_threshold on any edge, the result is scaled back down so it stays inside. That's the "make it fit, but never bigger than this fraction of the canvas" guardrail - the thing that keeps an aggressive ratio from blowing a layer past its container.
Inputs are width_a, height_a, width_b, height_b (all typed *, so they accept INT or FLOAT from anywhere), plus ratio (0.01–1). Outputs: width (INT), height (INT), and scale_ratio (FLOAT) - the multiplier that was applied, which is useful if you want to feed the same scale factor into a resize elsewhere.
Install
Part of ComfyUI-WBLESS:
cd ComfyUI/custom_nodes
git clone https://github.com/LaoMaoBoss/ComfyUI-WBLESS
restart ComfyUI, or install via ComfyUI Manager ("ComfyUI-WBLESS"). No dependencies or model files.
Troubleshooting
The subtle one is the cap. If your outputs look smaller than the ratio implies, enable_cap is on (it's the default) and the cap is clamping the result - that's the intended behavior, and lowering cap_threshold makes it clamp harder. If you want pure area math with no ceiling, flip enable_cap off. And remember the aspect ratio comes from group A: a square A and a wide B won't give you a wide result, because the node preserves A's shape. Pair this with the pack's Get Image Size / Get Mask Size and you've got a self-adjusting layout engine that resizes itself every run.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| width_a | * | — | |
| height_a | * | — | |
| width_b | * | — | |
| height_b | * | — | |
| ratio | FLOAT | 0.500.01–1 | — |
| cap_threshold | FLOAT | 0.700–1 | — |
| enable_cap | BOOLEAN | true | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| width | INT | — |
| height | INT | — |
| scale_ratio | FLOAT | — |