Center Calculation
Center Anything Without Doing the Math Yourself
- outer_with
- outer_height
- inner_with
- inner_height
- inner_x
- inner_y
Center Calculation is a two-rectangle math node. You give it the size of an outer box and a smaller inner box, and it hands back the x/y coordinates that drop the inner one dead center - plus a position knob that nudges it anywhere between the center and the edges. That's the whole node, and it earns its keep more than you'd guess.
Here's why you'd actually reach for it. ComfyUI constantly wants you to composite one thing onto another: a smaller latent onto a bigger canvas (LatentComposite), a logo or watermark over a generated image, a border, a QR code on a poster. Every one of those needs exact pixel offsets to place the inner element. And the numbers change whenever you swap a checkpoint or resolution - latent dimensions are multiples of 8 while your image dimensions are whatever you typed in - so the offset you hand-computed for one workflow is wrong in the next. This node makes the placement self-computing instead of a hardcoded guess.
How it works
It's one short function, and it does what you'd do in your head. For each axis it finds the leftover slack - outer minus inner, divided by two - and that's the centered offset. Then x_position and y_position (both clamped to -1..1) scale that slack: 0 means perfectly centered, 1 means shoved fully to one edge, -1 the other. It returns inner_x and inner_y as plain integers, which is what the composite nodes want.
The inputs that matter
There are only six, all required:
outer_with/outer_height- the big canvas. Yes, it's spelled "with" - the typo is in the actual code, so you'll see it on the node and in saved workflows. Just know it means width.inner_with/inner_height- the element you're placing.x_position/y_position- -1 to 1, the nudges. 0 is center; leave them there unless you actually want off-center placement.
Wiring the output
The node passes all four dimensions back through (outer_with, outer_height, inner_with, inner_height), which is convenient if you want to scale the inner element to match later. The two you care about are inner_x and inner_y - the top-left corner of the inner box. Feed those into a LatentComposite, or into any node that takes a paste/crop coordinate, and the inner element lands where you asked without you ever touching a calculator.
How to install
Both nodes in this pack install the same way. In ComfyUI Manager, search for ComfyUI-Calculation and hit install, or:
cd ComfyUI/custom_nodes
git clone https://github.com/Limitex/ComfyUI-Calculation
Then restart ComfyUI. There are no model downloads, and Center Calculation itself has zero Python dependencies beyond what ComfyUI already ships - it's pure arithmetic. (The pack does list pyqrcode and pypng for its QR node; Manager installs those for you automatically.)
Common issues & troubleshooting
- Inner bigger than outer produces negative offsets and nonsense placement. The node won't warn you - check your numbers.
x_positionis not a pixel offset. It's a fraction of the available slack, so 0.5 doesn't mean "half a pixel right," it means "halfway between center and the edge." If you want a specific pixel margin, you're better off doing that arithmetic elsewhere.- Off-by-one jitters from the
int()truncation are cosmetic and barely visible at generation sizes - don't chase them.
It's a boring little utility, and that's the compliment. When your layout math becomes a repeatable node instead of a scratch pad, your workflow stops breaking every time you change the resolution.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| outer_with | INT | 0 | — |
| outer_height | INT | 0 | — |
| inner_with | INT | 0 | — |
| inner_height | INT | 0 | — |
| x_position | FLOAT | 0.00-1–1 | — |
| y_position | FLOAT | 0.00-1–1 | — |
Outputs (6)
| Name | Type | Description |
|---|---|---|
| outer_with | INT | — |
| outer_height | INT | — |
| inner_with | INT | — |
| inner_height | INT | — |
| inner_x | INT | — |
| inner_y | INT | — |