Area Based Scale (Pixel)
Scale a transparent layer so its actual content matches a target pixel count
- image_alpha
- image
- scale_ratio
- scaled_width
- scaled_height
Here's a scaling problem the other nodes can't solve: you have a transparent cutout of a subject, and you want to size it so the subject itself occupies a certain fraction of a reference image - regardless of how much empty transparent space surrounds it in its own canvas. That's what Area Based Scale (Pixel) does. It counts the opaque pixels in your layer's alpha channel, compares that to the total pixels of a reference image, and returns the scale factor that makes the layer's real content match ratio of the reference.
The sibling Area Based Scale node works on the dimensions of group A. This one works on what's actually painted in the layer - which is the right tool when two cutouts have wildly different amounts of dead space around them, and you want their subjects to appear the same size relative to a background.
How it works
Three inputs, three outputs:
- image_alpha - your transparent layer (an image WITH alpha channel - the node reads channel 4 to count opaque pixels).
- image - the background/reference; its total pixel count is the baseline.
- ratio - target: layer's opaque pixels = reference pixels × ratio. Default 0.5, and this one goes up to 10.
The math is the fun part: it counts opaque pixels, computes target = reference_pixels × ratio, then works out the linear scale as the square root of the area ratio (because scaling both dimensions squares the area). Outputs are scale_ratio (the multiplier to apply to the layer), plus scaled_width and scaled_height - the layer's size after scaling.
The critical dependency: your layer must actually have alpha. The README is blunt about this - use it with ApplyMaskToAlpha, which converts a mask into a real transparency channel. Without alpha, every pixel counts as opaque and the node's math collapses to plain area scaling.
Install
Part of ComfyUI-WBLESS:
cd ComfyUI/custom_nodes
git clone https://github.com/LaoMaoBoss/ComfyUI-WBLESS
restart ComfyUI, or search "ComfyUI-WBLESS" in ComfyUI Manager. No models, no extra deps.
Troubleshooting
The whole pipeline breaks if the alpha is missing - feed it an opaque image and you'll get numbers that assume the entire canvas is content. That's the "use alongside ApplyMaskToAlpha" rule, and it's worth obeying. If the result seems to scale too little or too much, remember the ratio is about content pixels, not canvas size: a tiny subject with lots of surrounding transparency needs a big scale factor to reach the target. This is a genuinely clever node - the rare one that reasons about what's actually drawn rather than the bounding box - but it asks you to build the alpha pipeline correctly first.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| image_alpha | IMAGE | — | |
| image | IMAGE | — | |
| ratio | FLOAT | 0.500.01–10 | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| scale_ratio | FLOAT | — |
| scaled_width | INT | — |
| scaled_height | INT | — |