Nodes/ComfyUI-OneForOne/Image Fit Calculator
ComfyUI Node

Image Fit Calculator

It Does No Image Work — That's Exactly Why It's Useful

By Meettya·Created 2 years ago·Updated 4 months ago· 2
Image Fit Calculator
  • latent
  • image
  • IMAGE_WIDTH
  • IMAGE_HEIGHT
  • PAD_TOP
  • PAD_RIGHT
  • PAD_BOTTOM
  • PAD_LEFT
latent_scaleSD, Qwen (8x)
width_position0.50
height_position0.50
scale1.00

The "Image Fit Calculator" (class OFO Image Fit, from the tiny ComfyUI-OneForOne pack) has a name that oversells it, and that's the first thing to understand. It doesn't resize anything, it doesn't pad anything, and it definitely doesn't call some API. It is a pure arithmetic node: you feed it a latent and an image, and it spits out six integers telling you how big that image should be and where it should sit. The README says it plainly - "performs only computational tasks" - and the rest of your workflow has to do the actual work.

Why you'd reach for it

Every diffusion latent lives on an 8×8 grid. SD, SDXL, and Qwen compress by 8×, Flux2 by 16×, and a latent's dimensions have to stay multiples of that factor or you're asking the sampler to generate garbage. Now imagine you're doing an outpainting or img2img workflow: your input photo is, say, 1375×900, but your target canvas is 1152×896. You need it resized to fit inside that canvas (contain, not cover), you need the result rounded down to a multiple of 8, and then you need to know how many pixels of padding to add on each side so it lands centered - or shoved to one corner.

Doing that by hand means loading up a calculator and re-doing it every time you swap the image. The Image Fit Calculator is the person who does that math for you and hands the numbers to your other nodes.

How it works

The mechanism is right there in modules/image_tool.py and it's refreshingly honest. latent_scale tells it the factor ("SD, Qwen (8x)" → 8, "Flux2 (16x)" → 16), which it uses to convert your latent's dimensions into real pixels. It computes the largest scale that fits the image inside the canvas, applies your scale (0.1–1.0, default 1) if you want it smaller, then rounds the result down to the nearest multiple of 8 so it never overshoots the latent. Whatever space is left over becomes padding, distributed by width_position and height_position - both default to 0.5, i.e. centered; drop them toward 0 or 1 to pin the image to a side or corner.

The inputs you'll actually touch: latent_scale (set it to match your model or every number is wrong), and the two position floats if you want anything other than centered. Everything else defaults sensibly.

What comes out

Six INT outputs: IMAGE_WIDTH, IMAGE_HEIGHT, PAD_TOP, PAD_RIGHT, PAD_BOTTOM, PAD_LEFT. These wire straight into nodes that accept target dimensions and padding - the pack's own example workflow feeds the width/height into an upscaler's target-size inputs and the pads into ImagePadForOutpaint. Note the output order is top/right/bottom/left, so when you're connecting them, match PAD_LEFT to the left input on the next node, not the first one you see.

Installing it

No models, no heavy deps - the only dependency is numpy, which ComfyUI already ships. Install it via ComfyUI Manager (search "ComfyUI-OneForOne") or the manual route:

cd ComfyUI/custom_nodes
git clone https://github.com/Meettya/ComfyUI-OneForOne

Then restart ComfyUI. It'll appear under the "OneForOne" category.

Where people get burned

  • Expecting it to transform the image. It won't. Nothing happens on screen until you wire the numbers into a resize node and an image-padding node. That's the design, not a bug.
  • Wrong latent_scale. Leave the default "SD, Qwen (8x)" on a Flux2 latent and the pixel math is off by 2×, so your "fit" won't fit. Match it to your model's VAE.
  • The 8px rounding. Because it always rounds down to stay inside the latent, you can lose up to 7 pixels per side on a tight fit. The fix is baked in: nudge scale above 1.0 - oh wait, it caps at 1.0, so this node only ever shrinks. For a nearly-fitting image you may lose a sliver. Accept it or use a wider canvas.

It's a niche tool, and it's not the showpiece of anyone's workflow. But for canvas-and-pad pipelines it removes a whole class of "why is my outpaint misaligned" headaches, and it costs you nothing to try.

CategoryOneForOne

Inputs (6)

NameTypeDefaultDescription
latentLATENT
imageIMAGE
latent_scaleCOMBOSD, Qwen (8x)2 options: SD, Qwen (8x), Flux2 (16x)
width_positionoptFLOAT0.500–1
height_positionoptFLOAT0.500–1
scaleoptFLOAT1.000.1–1

Outputs (6)

NameTypeDescription
IMAGE_WIDTHINT
IMAGE_HEIGHTINT
PAD_TOPINT
PAD_RIGHTINT
PAD_BOTTOMINT
PAD_LEFTINT