Nodes/tdxh_node_comfyui/TdxhImageToSizeAdvanced
ComfyUI Node

TdxhImageToSizeAdvanced

Size your SDXL latent without doing the math

By youyegit·Created 3 years ago·Updated 5 months ago· 2
TdxhImageToSizeAdvanced
  • image
  • width_INT
  • height_INT
  • width_FLOAT
  • height_FLOAT
  • width_STRING
  • height_STRING
  • width_NUMBER
  • height_NUMBER
width768
height768
width_multiply_by_height1.0:(1024, 1024)
ratio1.0
what_to_follow

TdxhImageToSizeAdvanced is the smarter sibling of TdxhImageToSize. Same eight outputs (width/height in INT, FLOAT, STRING, and NUMBER), but instead of just reporting the image's size it computes a target size from a mode you pick, so you can size a latent to match an image while snapping everything to model-friendly values. It's the node in this pack most worth stealing.

The what_to_follow dropdown is the whole show, with seven modes:

  • only_width - use your width, scale the height to keep the image's aspect ratio, rounded to the nearest 8.
  • only_height - mirror image: fix height, scale width.
  • both_width_and_height - use your width and height exactly as given.
  • width * height - pick a preset pair from the width_multiply_by_height dropdown (41 SDXL ratio presets, from 0.25:(512, 2048) up to 4.0:(2048, 512)).
  • only_ratio - multiply the image's dimensions by the ratio slider (0–10, step 0.1), then snap both to multiples of 8.
  • only_image - just report the image's own size, like the basic node.
  • get_SDXL_best_size - snap the image's aspect ratio to the nearest of those same 41 SDXL-native buckets.

The 41 presets are the SDXL training ratio table - the same resolution buckets that show up in A1111's SDXL size suggestions and the official generative-models demo. get_SDXL_best_size does a nearest-ratio search over that table, so you can hand it a portrait phone photo and get back an SDXL-native size like 768×1344 instead of a weird non-multiple. That's the mode that keeps you from generating off-grid resolutions that warp or repeat - the tiling/artifacts class of problems you hit when you push a model far outside its training sizes.

The /8 snapping in the ratio and single-axis modes is the practical detail: latent models like multiples of 8, and the helper rounds rather than floors, so you don't silently lose pixels. Where you'd wire it: take the INT width/height outputs into EmptyLatentImage and you've got a latent that always lands on a valid size for whatever image you loaded.

Installing it

Same pack as the rest: ComfyUI Manager → search tdxh_node_comfyui → install → restart, or:

cd ComfyUI/custom_nodes
git clone https://github.com/youyegit/tdxh_node_comfyui

It sits under TDXH → tdxh_image after restart. No models needed. It's a hobbyist pack (GPL-3.0) and the README warns nodes can change between versions - worth a skim of the source before you rely on it in a production-ish pipeline, but for sizing math it's low-risk.

The honest take

get_SDXL_best_size alone is worth the pack. If you build SDXL img2img workflows from arbitrary reference images, this node saves you a calculator and a pile of trial-and-error generations. The other modes are conveniences; that one is a small superpower.

CategoryTDXH/tdxh_image

Inputs (6)

NameTypeDefaultDescription
imageIMAGE
widthINT768128–8192
heightINT768128–8192
width_multiply_by_heightCOMBO1.0:(1024, 1024)41 options: 0.25:(512, 2048), 0.26:(512, 1984), 0.27:(512, 1920), 0.28:(512, 1856), 0.32:(576, 1792), 0.33:(576, 1728), +35
ratioFLOAT1.00–10
what_to_followCOMBO7 options: only_width, only_height, both_width_and_height, width * height, only_ratio, only_image, +1

Outputs (8)

NameTypeDescription
width_INTINT
height_INTINT
width_FLOATFLOAT
height_FLOATFLOAT
width_STRINGSTRING
height_STRINGSTRING
width_NUMBERNUMBER
height_NUMBERNUMBER