ComfyUI Extension: resize_fill_background
Run ComfyUI workflows without the setup
No installs, no CUDA version roulette, no GPU sitting idle on your bill. Bring a workflow and run it in the browser.
A ComfyUI custom node that scales images proportionally and fills to specified dimensions with a solid color background, supporting size reduction and centered placement. (Description by CC)
Looking for a different extension?
Custom Nodes (0)
README
ComfyUI Resize & Fill Background
一个 ComfyUI 自定义节点,将图像等比缩放并用纯色背景填充到指定尺寸,支持按比例缩小图片并居中放置。
节点:Image Resize Fill Background
输入参数
| 参数 | 类型 | 默认值 | 说明 |
|------|------|--------|------|
| image | IMAGE | — | 输入图像 |
| width | INT | 512 | 目标画布宽度 |
| height | INT | 512 | 目标画布高度 |
| image_ratio | FLOAT | 1.0 | 图片占画布的线性比例(0.1~1.0) |
| fill_color | STRING | #FFFFFF | 背景填充颜色(十六进制) |
| method | ENUM | nearest-exact | 插值方法 |
处理逻辑
- 根据
image_ratio计算图片允许的最大区域:- 最大宽度 =
width × image_ratio - 最大高度 =
height × image_ratio
- 最大宽度 =
- 将原图等比缩放(contain)到该区域内
- 创建
width × height的纯色画布(颜色为fill_color) - 将缩放后的图片居中粘贴到画布上
image_ratio 示例(512×512 画布)
| image_ratio | 图片最大区域 | 四周边距 |
|----------------|-------------|---------|
| 1.0 | 512×512 | 无边距(普通 pad 缩放) |
| 0.75 | 384×384 | 各 64px |
| 0.5 | 256×256 | 各 128px |
| 0.25 | 128×128 | 各 192px |
当
image_ratio = 1.0时,效果等同于普通的 pad 缩放模式。
插值方法(method)
| 方法 | 说明 |
|------|------|
| nearest-exact | 最近邻,适合像素画 |
| bilinear | 双线性插值 |
| bicubic | 双三次插值 |
| lanczos | Lanczos 重采样,画质最好 |
输出
| 输出 | 类型 | 说明 |
|------|------|------|
| image | IMAGE | 处理后的图像 |
| WIDTH | INT | 输出宽度 |
| HEIGHT | INT | 输出高度 |
安装
将本文件夹放入 ComfyUI 的 custom_nodes 目录中,重启 ComfyUI 即可。
ComfyUI/
└── custom_nodes/
└── comfyui-resize-fill-background/
├── __init__.py
├── resize_fill_background.py
└── README.md
依赖
仅使用 ComfyUI 内置依赖(torch、Pillow、numpy),无需额外安装。
使用示例
示例 1:普通 Pad 缩放
将任意尺寸图片等比缩放为 512×512,留白用白色填充:
width: 512, height: 512, image_ratio: 1.0, fill_color: #FFFFFF
示例 2:图片缩小居中 + 纯色背景
将图片缩小到画布的 75%,居中在 512×512 白色画布上:
width: 512, height: 512, image_ratio: 0.75, fill_color: #FFFFFF
License
MIT
Run ComfyUI workflows without the setup
No installs, no CUDA version roulette, no GPU sitting idle on your bill. Bring a workflow and run it in the browser.