Nodes/NH-Nodes/Image Resize Unit (NH)
ComfyUI Node

Image Resize Unit (NH)

Millimetres, DPI and all

By jetthuangai·Created 5 months ago·Updated 21 days ago· 6
Image Resize Unit (NH)
  • image
  • image
  • width_px
  • height_px
unit
width_value1024.0
height_value1024.0
dpi300
resize_mode
resize_method
pad_color_hex#000000

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, or cm. In pixel mode, dpi is 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_ratio mode).
  • 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; area is 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 pad mode 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.

CategoryNH-Nodes/Image

Inputs (8)

NameTypeDefaultDescription
imageIMAGE
unitCOMBO3 options: pixel, mm, cm
width_valueFLOAT1024.00–100000
height_valueFLOAT1024.00–100000
dpiINT3001–2400
resize_modeCOMBO4 options: stretch, pad, crop, lock_ratio
resize_methodCOMBO6 options: nearest, bilinear, bicubic, area, nearest-exact, lanczos
pad_color_hexSTRING#000000

Outputs (3)

NameTypeDescription
imageIMAGE
width_pxINT
height_pxINT