Smart Resize π
Square up any image with border fill that matches its own edges
- image
- image
- width
- height
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.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | β | |
| longest_side | INT | 153664β8192 | Longest side target in pixels. Aspect ratio is always preserved. |
| multiple_of | INT | 81β64 | Snap both dimensions to a multiple of this value. Use 8 for SD/Flux. |
| interpolation | COMBO | Resampling method. Lanczos is sharpest for downscaling. | |
| upscale_if_smaller | BOOLEAN | true | Upscale images that are smaller than the target longest side. Turn off to only ever downscale, never upscale. |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | β |
| width | INT | β |
| height | INT | β |