PD:调整尺寸并填充图像
Fitting any image into a fixed canvas with padding, not cropping
- image
- image
You need every image in a batch to be exactly 512×512 - for a grid, a contact sheet, a consistent canvas for compositing - but you don't want to crop anything out. The answer is letterboxing, and that's this node's entire job: shrink the image to fit inside the target box, keep the aspect ratio, and pad the leftover space with white or black. In the UI it goes by its Chinese display name, "PD:调整尺寸并填充图像" (resize and fill image), which is honestly a clearer name than the class.
This is the "contain" behavior, not the "cover" behavior. Crop-based resizing is the ComfyUI default everywhere; fill is the mode people hand-roll with a resize plus a composite, which is exactly the plumbing this node removes.
How it works
It computes one scale factor - min(target_width / original_width, target_height / original_height) - so the image shrinks to fit entirely inside the box, then upscales/resizes using comfy.utils.common_upscale with your chosen interpolation. Next it builds a solid canvas of the full target size in the fill color (1.0 for white, 0.0 for black) and centers the resized image on it. Nothing is cropped; you just get padding bars on the two short sides.
The interpolation options come straight from ComfyUI's upscale vocabulary: area (default), bicubic, nearest-exact, bilinear, lanczos. area is the safe default for downscaling - it averages pixels rather than ringing - and lanczos is your best friend when the input is smaller than the target and you want it as sharp as possible.
The inputs that matter
image(IMAGE) - batchable.target_width/target_height(INT, 1–16384, default 512/512) - the canvas.fill_color-whiteorblack. White is the default, and it's the right one for most product/comic contexts; black if you're padding for a dark composite.interpolation-area/bicubic/nearest-exact/bilinear/lanczos.
The single output, image, is the padded result at exactly the target size.
Installing it
Part of Comfyui_PDuse by 7BEII. ComfyUI Manager (search "PDuse") or:
cd ComfyUI/custom_nodes
git clone https://github.com/7BEII/Comfyui_PDuse.git
cd Comfyui_PDuse
pip install -r requirements.txt
Restart. No models; pack deps are numpy, Pillow, scipy, opencv-python, torchvision. Docs are Chinese-first.
Where people get burned
Because it only ever shrinks to fit, an image whose aspect ratio is far from the target (say a 9:16 image into a 1:1 box) comes out with huge padding bars - you asked for no cropping, so that's what you get; if you want it cropped instead, look at the pack's crop/resize nodes or core ComfyUI's ImageScale. Also, the padding is solid color, not a blurred mirror or transparency - if you need see-through bars for compositing, this isn't the node. And note upscaling small images here is just resampling, not the model-based upscale you'd want for real detail recovery.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| target_width | INT | 5121–16384 | — |
| target_height | INT | 5121–16384 | — |
| fill_color | COMBO | white | 2 options: white, black |
| interpolation | COMBO | area | 5 options: area, bicubic, nearest-exact, bilinear, lanczos |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |