PDimage_resize_V2
PDimage_resize_V2 — aspect-ratio resizing with letterbox, crop, and a transparency safety
- pixels
- mask_optional
- IMAGE
- MASK
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.
Inputs (11)
| Name | Type | Default | Description |
|---|---|---|---|
| pixels | IMAGE | — | |
| aspect_ratio | COMBO | original | 11 options: original, custom, 1:1, 3:2, 4:3, 16:9, +5 |
| proportional_width | INT | 11–9999 | — |
| proportional_height | INT | 11–9999 | — |
| fit | COMBO | crop | 3 options: letterbox, crop, fill |
| method | COMBO | lanczos | 6 options: lanczos, bicubic, hamming, bilinear, box, nearest |
| scale_to_side | COMBO | longest | 4 options: longest, shortest, width, height |
| scale_to_length | INT | 102416–16777216 | — |
| round_to_multiple | COMBO | 8 | 9 options: None, 4, 8, 16, 32, 64, +3 |
| background_color | STRING | #000000 | — |
| mask_optionalopt | MASK | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |
| MASK | MASK | — |