Nodes/ComfyUI-CraftKit/Smart Resize πŸ“
ComfyUI Node

Smart Resize πŸ“

Square up any image with border fill that matches its own edges

By CraftopiaStudioΒ·Created 6 months agoΒ·Updated 12 days agoΒ· 2
Smart Resize πŸ“
  • image
  • image
  • width
  • height
β—„longest_side1536β–Ί
β—„multiple_of8β–Ί
β—„interpolationβ–Ύβ–Ί
β—„upscale_if_smallertrueβ–Ί

Smart Resize with Border Fill exists to solve one boring, endlessly annoying problem: you have images of mixed aspect ratios and you need them all square. The default answer - pad with black - looks terrible. The lazier answer - squash to fit - distorts everything. This node does the version you actually want: it makes everything exactly target_size square by cropping the excess on the long side and filling the short side with a color sampled from the image's own edge.

So if you feed it a 2048Γ—1024 landscape photo, it center-crops the width down to 1024 and pads the vertical gap with a color pulled from the top and bottom edges. The result reads as "this image was meant to be square," not "someone glued a black bar onto it." That makes it a genuinely useful tool for building training datasets or prepping frames for video models that want a fixed square latent - the KB's upscaling essay draws a hard line between "add pixels" and "add detail," and this is neither: it's a geometric normalizer, part of the batch-prep layer of a workflow, not a quality play.

Three inputs matter. target_size (64–8192, default 1024) is the output side length - it's always a square, there's no width/height pair. border_sample_size (1–50, default 5) is how many rows or columns of pixels from each edge get sampled to compute the fill color. color_method picks between mean and mode: mean averages the edge pixels, which is smoother for photographic content; mode picks the single most common color after rounding, which suits flat-color or pixel-art content where an average would smear into a muddy blend.

Mechanically it's straightforward and worth understanding for the traps. It works on one frame: the first image in a batch (image[0]), so a batch of 16 frames only gets the first resized. Oversized dimensions are center-cropped, undersized ones are padded with the per-edge color (left/right and top/bottom are sampled independently), and it processes width then height. The result is always exactly target_size on both sides.

The real trap for beginners is the hidden dependency. The node's module imports scipy at the top, and this pack ships no requirements.txt - it's advertised as zero-dependency, and it mostly is, but scipy isn't a guaranteed part of a minimal ComfyUI install. If the whole pack fails to import with an error about scipy (or scikit-learn, its sibling Pixel Art Normalizer pulls that in), that's why. pip install scipy scikit-learn fixes both.

If you need non-square output, look elsewhere. And if your job is actually upscaling rather than squaring up, this is the wrong tool - that's Nearest Neighbor Upscale's lane. Install via ComfyUI Manager (search "AnotherUtils") or clone https://github.com/marcoc2/ComfyUI-AnotherUtils into custom_nodes, then restart.

CategoryCraftKit

Inputs (5)

NameTypeDefaultDescription
imageIMAGEβ€”
longest_sideINT153664–8192Longest side target in pixels. Aspect ratio is always preserved.
multiple_ofINT81–64Snap both dimensions to a multiple of this value. Use 8 for SD/Flux.
interpolationCOMBOResampling method. Lanczos is sharpest for downscaling.
upscale_if_smallerBOOLEANtrueUpscale images that are smaller than the target longest side. Turn off to only ever downscale, never upscale.

Outputs (3)

NameTypeDescription
imageIMAGEβ€”
widthINTβ€”
heightINTβ€”