Snap Area
Count black or white pixels so your subject hits the right % of the frame
- image
- 面积
- 占比%
Snap Area counts pixels. Give it an image, tell it whether you care about black or white, and it returns two integers: the raw pixel count of that color and what percentage of the whole frame it covers. That's the entire node, and honestly that's what makes it useful - it answers a question ComfyUI's built-in nodes never ask.
The author says he built it because nothing in ComfyUI could compute area size and ratio "to a whole number," which he needed for his automated "Majic product" e-commerce workflow. If you do product or listing photography, the use case writes itself: many marketplace and print workflows want the subject to occupy a specific fraction of the frame, and eyeballing that gets old fast. This is also handy for sanity-checking compositing - after a background-removal or a canvas compositing step, you can verify the product really fills 60% and the white background really is 40%.
How it works
Mechanically it's simple: the image gets converted to grayscale, then everything is compared against a hardcoded threshold of 0.5. Choose black and every pixel below 0.5 counts; choose white and every pixel at or above 0.5 counts. It returns the count and the rounded percentage of the total.
One quirk worth knowing: the "area" is counted per channel, so on a normal RGB image a fully black pixel counts roughly three times. The percentage stays correct - it's a ratio of the same counting scheme - but if the absolute number matters to you, feed it a single-channel mask instead of an RGB image.
Inputs
- image (IMAGE) - anything with pixels.
- color_choice (enum:
black/white) - which color to count.
Outputs
Two integers, and note they're labeled in Chinese in the UI:
- 面积 - the total area (pixel count) of the selected color.
- 占比% - that area as a rounded percentage of the entire image.
Install
Same pack as the rest - ComfyUI Manager, search "Snap Processing", or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/SS-snap/ComfyUI-Snap_Processing
cd ComfyUI-Snap_Processing
pip install -r requirements.txt # just pyqt5
Restart ComfyUI. Only dependency is PyQt5; no models to download.
Where people get burned
- The threshold is fixed at 0.5. No tolerance slider, no fuzziness. Pure-ish black or white counts; antialiased edges, gray gradients, and semi-transparent overlaps don't. Don't feed it JPEG-compressed products and expect exact numbers.
- Only black or white. There's no color picker - if your subject isn't one of those two, this node can't measure it.
- The percentage truncates. The ratio is computed with
int(), so 59.9% reports as 59. Fine for "is it roughly a third?" checks, wrong if you need precision. - It measures share of the whole image, not anything spatial. Same percentage could mean one big centered blob or ten scattered specks - the node doesn't know or care where the color is.
For a quick "did my subject end up the right size on the canvas" check, it's exactly what you want. For anything subtler, you'd want a proper mask-based measurement.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| color_choice | COMBO | 2 options: black, white |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| 面积 | INT | — |
| 占比% | INT | — |