Calculate Image Megapixels
Your image is 2048x2048 — is that 4 megapixels? Stop doing mental math
- image
- megapixels
Ever look at an image and genuinely not know whether 1536×1024 counts as a "1.5 megapixel" image? It does, but you shouldn't have to carry that arithmetic around. Calculate Image Megapixels (class ImageMegapixels) is a one-input, one-output utility that reads the resolution off any image in your graph and hands you a clean float - no model, no settings, no math.
It's the first node from comfyui-ntools, a brand-new pack whose whole pitch is "essential little utilities that should have been in ComfyUI from day one." That's a fair read of this one: it's the kind of node you didn't know you wanted until you're staring at a workflow and wondering why everyone keeps saying "keep it under 1 megapixel."
How it works
ComfyUI images aren't files, they're 4D tensors shaped [batch, height, width, channels]. This node reads the height and width off that tensor, multiplies them, and divides by a million - that's the entire implementation, a couple of lines of Python.
Two details worth knowing:
- It uses decimal megapixels (divide by 1,000,000), the same convention camera marketing uses. A 2048×2048 image returns
4.19, which is exactly the example in the pack's README. - It reports resolution per image, not per batch. A batch of four 1024×1024 images still returns
1.05, because every frame in a batch tensor shares the same height and width. If you're processing a video and expecting total pixel volume, this won't give it to you.
It's also defensive: if it gets None or something that isn't a proper 4D tensor, it quietly returns 0.0 instead of crashing your graph. That's the sort of small courtesy a lot of utility nodes skip.
The one input and the one output
You genuinely only have one knob here:
- image (IMAGE) - required. Feed it any image output from a VAE decode, a load node, an upscaler, whatever.
- megapixels (FLOAT) - the output. Plain number, ready to wire into anything that takes a float.
One trap for beginners: this node is not an output node, so nothing displays on its own. Connect megapixels to a text/display node if you just want to see the number, or pipe it into a compare or branch node to make decisions off it. As a plain float it's perfect for that - no string parsing, no counting digits.
Why you'd actually reach for it
Resolution checks show up all over real workflows. Every model family has a native megapixel band - SD 1.5 lives around 0.26 MP, SDXL around 1.0, Flux comfortably above that - and going far past it is how you get tiled patterns and double hands. And upscaling is where it really earns its keep: the Comfy Org handbook's best-known tip is to downscale a soft source to ~0.35 megapixels before feeding it to an upscaler like SeedVR2, because there's no detail at full resolution to recover. Dropping this node in tells you at a glance whether your input is already in that territory.
Installing it
It's a normal custom node, so either route works:
cd ComfyUI/custom_nodes
git clone https://github.com/nitingrg/comfyui-ntools
# restart ComfyUI
Or open ComfyUI Manager → Custom Nodes Manager, search "comfyui-ntools", and hit Install. Wherever it goes, you'll find it under the ntools group in the node menu.
No dependencies, no model downloads, no requirements.txt - the only import is torch, which ComfyUI already ships. Install is genuinely zero-friction, which is more than you can say for most of the ecosystem.
Gotchas
- The README's clone command is wrong. It literally says
git clone https://github.com/yourusername/comfyui-ntools.git. Usenitingrg- the real URL above - or you'll clone nothing. - Manage expectations on "actively maintained." The pack is one commit old with a single node and a "more coming soon" roadmap. That's fine for something this small, but don't count on a fleet of utilities materializing next week.
- The silver lining of a node this tiny: you can read all of its source in about 30 seconds and verify exactly what it does. There's no behavior hiding anywhere.
Is it essential? Honestly, no - you can do this math in your head, or with a Show Text node and a calculator app. But if you're building workflows that branch on resolution, having a node that returns the truth as a number instead of as vibes is worth the one-time install.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| megapixels | FLOAT | — |