Image Resize Unit (NH)
Millimetres, DPI and all
- image
- image
- width_px
- height_px
ComfyUI resizes in pixels, and pixels are useless when someone asks for "a 15 cm print at 300 DPI." Image Resize Unit (NH) lets you size images in the units the physical world uses - pixel, millimetre, or centimetre - with a dpi setting doing the pixel↔unit math for you. It's the node that makes your ComfyUI output actually printable, or at least sized the way a client asked for it.
The DPI conversion is the whole personality of this node. 15 cm at 300 DPI means a specific pixel count, and this node computes it instead of making you do division in your head.
How it works
- unit -
pixel,mm, orcm. In pixel mode,dpiis ignored and you're just doing a normal resize. - width_value / height_value - the target size in that unit. Set either to 0 to let the other side drive (important in
lock_ratiomode). - dpi - dots per inch, the bridge between pixels and physical size. Default 300, the print standard.
- resize_mode - how the image fits the target:
- stretch - distort to exactly the target.
- pad - scale to fit inside, letterbox with
pad_color_hex. - crop - scale to cover, center-crop the overflow.
- lock_ratio - scale to fit while keeping aspect ratio, no crop and no pad. The one you'll reach for most with a single dimension given.
- resize_method -
nearest,bilinear,bicubic,area,nearest-exact,lanczos. Lanczos is the default-quality pick for downscaling;areais the right choice for aggressive downscales where you want anti-aliasing that holds texture. For upscaling, you'll generally want something smoother than nearest. - pad_color_hex - the letterbox color when
padmode leaves bars.
Outputs
Beyond the resized image, you get width_px and height_px - the actual pixel dimensions of the result. These are gold for print pipelines: save them as metadata, or feed them to a Save Image caption so your file records exactly what size it was produced at. In lock_ratio mode especially, the actual result differs from your nominal target, so the *_px outputs are the source of truth.
The honest caveats
This node resizes the pixel grid - it doesn't invent resolution or re-encode DPI metadata into the file. A 15 cm × 10 cm print at 300 DPI needs ~1772 × 1181 pixels; if your source is 512 × 512, you're upscaling, and upscaling can't conjure detail that was never there. For print work, this node pairs best with an upscaler upstream (see the tiling notes on Image Tile (NH)) so the model adds detail before the final unit resize.
Installing
Part of NH-Nodes:
cd ComfyUI/custom_nodes
git clone https://github.com/jetthuangai/NH-Nodes.git
cd NH-Nodes
pip install -r requirements.txt
Or search NH-Nodes in ComfyUI Manager and restart. No models, no downloads - PIL/comfy resize math with a unit converter in front.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| unit | COMBO | 3 options: pixel, mm, cm | |
| width_value | FLOAT | 1024.00–100000 | — |
| height_value | FLOAT | 1024.00–100000 | — |
| dpi | INT | 3001–2400 | — |
| resize_mode | COMBO | 4 options: stretch, pad, crop, lock_ratio | |
| resize_method | COMBO | 6 options: nearest, bilinear, bicubic, area, nearest-exact, lanczos | |
| pad_color_hex | STRING | #000000 | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| width_px | INT | — |
| height_px | INT | — |