Nodes/Comfyui_PDuse/PD_image resize by ratio
ComfyUI Node

PD_image resize by ratio

PD_image resize by ratio — center-crop to an aspect ratio, then fit the long edge

By 7BEII·Created 2 years ago·Updated 15 days ago· 53
PD_image resize by ratio
  • images
  • processed_images
  • info
max_size1024
aspect_width3
aspect_height4
resampling_methodLANCZOS

Here's the workflow problem this node solves: you have images in arbitrary shapes, and you need them all to be 3:4 at 1024 on the long edge - a specific aspect ratio at a specific max size. PD_image resize by ratio does both steps in one pass: it center-crops each image to the requested aspect ratio, then resizes so the longest side lands on max_size. Two jobs, one node, and a string output that tells you exactly what it did to each image.

It's the classic pre-trainer or pre-batch normalization move: get every sample to the same ratio and scale so the model never has to guess.

How it works

Per image, it compares the current aspect ratio against aspect_width : aspect_height (defaults 3:4). If they differ by more than 1%, it crops:

  • image too wide → trims width from both sides (center crop) to hit the ratio.
  • image too tall → trims height from top and bottom.

Then it computes the target size from max_size and the ratio - wide ratio (3:2) uses max_size for width, tall ratio (2:3) uses it for height - and resizes with the chosen resampling_method (default LANCZOS). Alpha handling is sensible: RGBA inputs get composited onto a white background before processing, so transparent PNGs don't produce a black halo (it's an RGB-output node, keep that in mind if you need to preserve transparency).

The info output is where the transparency of this node lives: one line per image like original: 1200x1600 -> final: 768x1024 (cropped width: 1200 -> 900). Wire that into a text display and you can audit an entire batch's transforms without guessing.

The inputs that matter

  • images (IMAGE) - the batch.
  • max_size (INT, default 1024, 64–4096) - target length of the longest side.
  • aspect_width / aspect_height (INT, default 3 / 4) - the ratio you're standardizing to.
  • resampling_method - LANCZOS (default) / BICUBIC / BILINEAR / NEAREST.

Outputs: processed_images (IMAGE) and info (STRING).

When to reach for it

Training-data normalization is the headline: every sample ends up the same ratio at the same scale, which is what most dataset loaders and trainers want before augmentation. It's also great for standardizing a comparison grid or prepping a slideshow where all frames must share a frame shape. If your images are already close to the target ratio, the crop step is skipped entirely and it's just a clean long-edge resize.

Gotchas

The crop is always center - there's no anchor input, so if the content you care about lives at an edge (a face at the top of a 16:9 frame cropped to 1:1), the center crop can chop it. For edge-anchored jobs, use a coordinate crop first, then this node for the ratio/scale step. Also note it's lossy-by-design (crop + resample), so don't use it as your archive path. And the RGBA-to-white flattening means transparency is dropped - if you need alpha to survive, pair the crop/resize with a mask-carrying node instead.

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 PD_image resize by ratio under PD_Image/Processing. Crop to ratio, fit to size, report the results - a genuinely useful two-in-one.

CategoryPD_Image/Processing

Inputs (5)

NameTypeDefaultDescription
imagesIMAGE
max_sizeINT102464–4096
aspect_widthINT31–16
aspect_heightINT41–16
resampling_methodCOMBOLANCZOS4 options: LANCZOS, BICUBIC, BILINEAR, NEAREST

Outputs (2)

NameTypeDescription
processed_imagesIMAGE
infoSTRING