Nodes/ComfyUI-XJNodes/Image Scale Calc
ComfyUI Node

Image Scale Calc

A scale calculator that hands ComfyUI the numbers it actually wants

By alexjx·Created 10 months ago·Updated 4 months ago· 0
Image Scale Calc
  • image
  • width
  • height
scale1.0
divide_by0

The name tells you exactly what this node does, which is more than most names in this pack manage: it computes scaled dimensions and hands them back as plain integers. It does not resize anything. You feed it an image and a scale factor, it reads the image's current width and height, multiplies, and outputs the two numbers you'd have done in your head if you trusted yourself with arithmetic.

So why does this node exist at all? Because ComfyUI's resizing story is fiddly in a specific way. Native resize nodes want exact target dimensions, and lots of workflows want those dimensions to land on a multiple of 8 or 64 - latent spaces are picky, and the difference between 512 and 513 quietly degrades results or throws shape errors. The divide_by input exists exactly for that. Set it to 8 and the node rounds your computed size up to the nearest multiple of 8. That's the whole value proposition, and it's a real one if you've ever sat there with a calculator deciding whether to resize to 832 or 896.

How it works

The mechanism is about as simple as a node can be. It looks at the image tensor shape (batch, height, width, channels), multiplies width and height by scale, and - if divide_by is above zero - rounds each result up so it's divisible by that number. The rounding is ((n + d - 1) // d) * d, which is ceil-to-multiple, not nearest-multiple. Worth knowing if you're feeding the output into something that expects a specific size: 1024 at scale 1.0 with divide_by 64 stays 1024, but a computed 1025 becomes 1088, not 1024.

Note the int conversion truncates the float before rounding kicks in. A computed 639.6 becomes 639, then 640 with divide_by 8. Fine in practice, but don't expect mathematically exact results - expect numbers that work in a graph.

Inputs and outputs

The three inputs are the whole story:

  • image - any IMAGE tensor; only its dimensions are read, so it costs nothing to wire in a preview image or a latent's source
  • scale - a FLOAT from 0.1 to 10, default 1.0. This is your resize factor
  • divide_by - an INT, default 0 (off). Set to 8, 16, 64, whatever your model wants to be divisible by

Outputs are width and height as INTs. Wire them into any node that accepts size inputs - an Image Resize, an EmptyLatentImage, a KSampler's size-adjacent math, an Ultimate SD Upscale's target fields. If the resize node you're using doesn't take width/height wires, you can right-click the widget, convert it to input, and plug the numbers in.

Installing it

This is one node in the XJNodes pack, so it arrives with all the others. Easiest path is ComfyUI Manager: search for "ComfyUI-XJNodes", install, restart. By hand:

cd ComfyUI/custom_nodes
git clone https://github.com/alexjx/ComfyUI-XJNodes
# restart ComfyUI

There's no requirements.txt to install - the pack runs on torch, numpy, and Pillow, all of which ComfyUI already ships. Just restart and it appears under the XJNodes/image category. The pack is GPL-3.0 and the README is upfront that it's built for the author's personal use, which is your warning that polish is "works for me" level.

Where people get burned

The classic mistake is expecting the image back. This node returns numbers, period. If you wire its output into a PreviewImage you'll get a type error and a confused afternoon. Pair it with an actual resize node - the numbers here are the target, the resize is a different node's job. And remember the ceiling rounding: with divide_by set, the output is never smaller than what you asked for, only equal or bigger. That's the desired behavior for latent multiples, but it trips people up when they're trying to hit an exact pixel count.

For a node that actually performs the resizing with megapixel targets instead of scale factors, XJNodes also ships Image Scale Megapixel - that one's the sibling worth grabbing when you care about total resolution rather than a multiplier.

CategoryXJNodes/image

Inputs (3)

NameTypeDefaultDescription
imageIMAGE
scaleFLOAT1.00.1–10
divide_byoptINT00–128

Outputs (2)

NameTypeDescription
widthINT
heightINT