Nodes/ComfyUI-Przewodo-Utils/Image Scale Factor
ComfyUI Node

Image Scale Factor

Let a node do the resize math for you

By przewodo·Created about a year ago·Updated 4 months ago· 4
Image Scale Factor
  • image
  • scale_factor
final_size1024

Every time you resize an image in ComfyUI you have to decide how much. With the built-in ImageScale node you type a number, but "how many times bigger should this be" usually isn't the question - the question is "I want the long side to be 1024." Doing that arithmetic in your head every run is exactly the kind of thing a node should own. This one does: you feed it an image and a target size, and it hands back the scale factor you need to get there, while keeping the aspect ratio.

Think of it as the calculation half of an upscale pipeline. In an upscaling workflow you often want to scale an image so its long edge lands on a specific number (say, the native resolution of your model) before you do the real upscale pass. This node feeds its scale_factor output into an ImageScale / ImageScaleBy node as the multiplier, and you never have to compute 1024 / current_width again.

How it works

The math is exactly what you'd do by hand, and it only cares about the larger side:

  1. Read the image's width and height from the tensor shape.
  2. Find which side is bigger.
  3. scale_factor = final_size / current_larger_side.

Because only the larger side is involved, the aspect ratio is preserved automatically - the smaller side scales by the same factor. Feed the result into a standard scale-by-factor node and the long edge lands on your target.

The inputs that matter

  • image - any IMAGE. The node just needs its dimensions, so the actual content is irrelevant.
  • final_size - the target length for the larger side, in pixels. Default 1024.

One output: scale_factor, a FLOAT, ready to drop into an ImageScaleBy or any node that takes a float multiplier.

Installing it

Part of ComfyUI-Przewodo-Utils. ComfyUI Manager → search the pack, or:

cd ComfyUI/custom_nodes
git clone https://github.com/przewodo/ComfyUI-Przewodo-Utils.git

Restart. No dependencies beyond the ones ComfyUI already has.

Where people get tripped up

The big mental model is the target is the long side, not the average or the width. Feed in a portrait image with final_size = 1024 and you get the height at 1024, width proportionally smaller - if you were expecting both sides to hit 1024 (a square crop), this isn't that node.

Second, note that scale factors here are meant to be multipliers, not absolute sizes. If your downstream scale node takes an absolute width/height instead of a multiplier, you'll need a different node - or wire this into something that converts. It's a small, single-purpose tool, but for the "fit the long edge to a model-friendly size" chore it removes real tedium, and it keeps your workflow honest when you change input resolutions: re-run, and the factor recomputes itself.

CategoryPrzewodoUtils

Inputs (2)

NameTypeDefaultDescription
imageIMAGEInput image to calculate scale factor for. The node will analyze the image dimensions to determine scaling.
final_sizeINT1024Target size for the larger side of the image. The scale factor will be calculated to resize the larger dimension to this value while maintaining aspect ratio.

Outputs (1)

NameTypeDescription
scale_factorFLOAT