Nodes/Comfyui_PDuse/PDimage_resize_V2
ComfyUI Node

PDimage_resize_V2

PDimage_resize_V2 — aspect-ratio resizing with letterbox, crop, and a transparency safety

By 7BEII·Created 2 years ago·Updated 15 days ago· 53
PDimage_resize_V2
  • pixels
  • mask_optional
  • IMAGE
  • MASK
aspect_ratiooriginal
proportional_width1
proportional_height1
fitcrop
methodlanczos
scale_to_sidelongest
scale_to_length1024
round_to_multiple8
background_color#000000

PDimage_resize_V2 is the pack's most feature-complete resize node, and the author is upfront that it's a faithful recreation of the well-known LayerUtility: ImageScaleByAspectRatio V2 - same parameters, same behavior, reimplemented. What that buys you: aspect-ratio-aware resizing with real fit options (letterbox / crop / fill), a choice of which side to scale by (longest / shortest / width / height), a round_to_multiple safety, a configurable background color for letterboxing, and - unusually - a mask output that follows the image.

If you only install one resize node from this pack, this is it.

How it works

The flow is: pick a target aspect ratio (original, custom via proportional inputs, or a preset like 1:1/3:2/4:3/16:9/2:3/9:16), compute base dimensions from scale_to_side + scale_to_length (longest side 1024 by default), then apply the fit behavior:

  • letterbox - scale to fit inside, pad the rest with background_color (a hex string like #000000).
  • crop - scale up to cover, center-crop the overflow.
  • fill - stretch to the exact target (distorts).

Then round_to_multiple snaps dimensions to a multiple (default 8), method picks the resample filter (lanczos default, plus bicubic/hamming/bilinear/box/nearest), and the optional mask_optional input is processed alongside so image and mask come out registered.

The inputs that matter

  • pixels (IMAGE) - source.
  • aspect_ratio - original (default) / custom / presets.
  • proportional_width / proportional_height - used when aspect_ratio = custom.
  • fit - letterbox / crop (default) / fill.
  • scale_to_side + scale_to_length - which side the target length applies to and what it is (default longest, 1024).
  • round_to_multiple - None / 4 / 8 (default) / 16 / … / 512.
  • background_color - hex string for letterbox padding.
  • mask_optional (MASK, optional).

Outputs: IMAGE and MASK.

The transparency safety net you should know about

This is the README's most-emphasized behavior, and it's a real trap that the author built an escape hatch for: a fully-transparent image passed through resize can come back with ugly black or white edges when composited later. The node checks - if the connected mask_optional is all-ones (i.e., the image reads as entirely transparent), it returns the image and mask unchanged, no resize. The README spells out the pairing that makes this work for transparent PNGs:

Load Image.IMAGE -> PDimage_resize_V2.pixels
Load Image.MASK  -> PDimage_resize_V2.mask_optional

Always wire the mask for transparent assets. If you see a resize silently do nothing, check whether your mask is all-ones - that's this guard, not a bug.

Where to use it

Standardizing batches to a model-friendly ratio with letterbox (the background_color is the killer feature vs. core's black-only padding), cover-cropping a mixed batch to a fixed canvas, and any pipeline that needs image + mask resized in lockstep. It's the node you'd wire between Load Image and a blend/composite step.

Gotchas

round_to_multiple and fit: crop together can produce a slightly smaller canvas than you asked (cropping to a multiple shaves pixels) - fine for latents, surprising if you demanded exact 1024. And remember original ratio means "keep whatever the image has," so changing only scale_to_length with original just scales it up or down without forcing a shape.

Install

ComfyUI Manager: search PDuse (repo 7BEII/Comfyui_PDuse), install, restart. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/7BEII/Comfyui_PDuse
cd Comfyui_PDuse
pip install -r requirements.txt

Restart and it appears as PDimage_resize_V2 under PDuse/Image. The most capable resize in the pack - and the one that already thought about your transparent PNGs.

CategoryPDuse/Image

Inputs (11)

NameTypeDefaultDescription
pixelsIMAGE
aspect_ratioCOMBOoriginal11 options: original, custom, 1:1, 3:2, 4:3, 16:9, +5
proportional_widthINT11–9999
proportional_heightINT11–9999
fitCOMBOcrop3 options: letterbox, crop, fill
methodCOMBOlanczos6 options: lanczos, bicubic, hamming, bilinear, box, nearest
scale_to_sideCOMBOlongest4 options: longest, shortest, width, height
scale_to_lengthINT102416–16777216
round_to_multipleCOMBO89 options: None, 4, 8, 16, 32, 64, +3
background_colorSTRING#000000
mask_optionaloptMASK

Outputs (2)

NameTypeDescription
IMAGEIMAGE
MASKMASK