Image Downscale By W&H
Downscale to an exact width and height, pixels intact
- image
- out_img
- width
- height
Sometimes "shrink by a factor" isn't what you need - you need to hit a specific width and height, exactly, right now, because the next node wants a 512x512 latent or your canvas is fixed at 384x640. This node does that for pixel art the safe way: it resizes to the exact target dimensions using nearest-neighbor resampling, so the hard block edges of the sprite survive instead of getting smeared by a smoother filter. It's the exact-size sibling of the pack's Image Downscale By Factor node.
How it works
It calls straight into ComfyUI's own comfy.utils.common_upscale with the nearest-exact upscale method - the same plumbing ComfyUI core uses for image resizing, which means it behaves like a first-class ComfyUI citizen (proper channel handling, batched input support) rather than a hand-rolled resize. One detail in the code worth knowing: the optional crop input, with two choices, disabled and center. If you hand it a width/height that doesn't match your image's aspect ratio, disabled will stretch it to fit - a 512x512 target on a 4:3 image becomes distorted squares. center center-crops the image to the target aspect ratio first, then resizes, so the pixels stay undistorted and you just lose some edges instead of mashing the geometry.
Inputs and outputs
- image - what you're shrinking.
- width (INT, default 512, range 0–4096) and height (INT, default 512, range 0–4096) - the exact target dimensions.
- crop (optional enum, default
disabled) -centerto preserve aspect ratio via center crop,disabledfor a straight stretch.
Outputs: out_img, plus width and height reporting what the resize actually produced - satisfying to confirm, and useful when you're feeding the result into something that needs the numbers.
Installing it
Same single pack as every node here:
cd ComfyUI/custom_nodes
git clone https://github.com/AhBumm/ComfyUI_UnfakePy_Warpper
or ComfyUI Manager → search ComfyUI_UnfakePy_Warpper, then restart. Deps: unfake==1.0.7 + nest_asyncio (unfake brings opencv, Pillow, NumPy; Python 3.10+). No models, no GPU.
The honest trade-off
Nearest-neighbor to an exact size means one thing to keep straight: if the target isn't an integer multiple of your source, the block sizes will be uneven - some "pixels" end up a hair bigger than their neighbors, because nearest-neighbor can't subdivide a block. For pixel art that's usually invisible at a glance but it's why the pack also offers integer scaling (Image Upscale By Integer) when you just want clean multiples. Reach for this node when a fixed canvas or latent size is the constraint and you accept nearest-neighbor as the pixel-safe way to meet it - it's the difference between blocky-but-crisp and smooth-but-blurry.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| width | INT | 5120–4096 | — |
| height | INT | 5120–4096 | — |
| cropopt | COMBO | 2 options: disabled, center |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| out_img | IMAGE | — |
| width | INT | — |
| height | INT | — |