ZML_添加纯色背景
The padding node that stops your crops from looking cramped
- 图像
- 图像
Ever composite a cutout onto a new background and immediately notice the subject touches the edges, or the padded area is transparent where you wanted solid white? ZML_AddSolidColorBackground (ZML_添加纯色背景) is the fix: it expands your image outwards with a solid-color border. White, black, green, or transparent, on whichever sides you ask for.
What it is
This is the "add canvas around an existing image" node - think of it as the opposite of cropping. It shows up in ComfyUI-ZML-Image, the big utility pack from Chinese developer zml-w, and it pairs naturally with the pack's trim/limit nodes: the README literally describes a workflow where you fill to a ratio with a background node, then use another node to cut the leftover background off. It's a small deterministic pixel operation, in the same family as everything in the post-processing layer - zero model, zero inference, instant on a batch.
The inputs that matter:
- 图像 (IMAGE) - what you're padding.
- 处理模式 - the interesting one. 矩形 pads a plain rectangle. 无固定形状 (no fixed shape) looks at the actual subject's outline: if your image has an alpha channel it detects the silhouette and draws the border around the contour, not the bounding box. 透明转纯色 (transparent→solid) is for converting an RGBA image with a transparent background into one with a flat color background - your cheap rembg cleanup step.
- 背景颜色 - 白色 / 黑色 / 绿色 / 透明. Green is a classic if you're going to key it out later; transparent keeps alpha around the subject.
- 外拓像素 (INT, 50) - how many pixels of border to add.
- 外拓方向 - 全方向 (all around) or just top/bottom/left/right in any combination. Adding only downward gives you room for a caption strip under the subject.
Output is a single 图像, ready to feed a Save or a Composer.
How it works
The implementation is plain PIL plus NumPy: it converts your tensor to a PIL image, expands the canvas in the requested directions, and fills the new area with the chosen color. In 无固定形状 mode it uses the alpha channel to find the subject's bounding contour and pads around that silhouette instead of the image edges - which is how you get that "character with a nice colored margin" look without the subject's head being one pixel from the top.
Install and gotchas
Same as every node in this pack:
cd ComfyUI/custom_nodes
git clone https://github.com/zml-w/ComfyUI-ZML-Image
or find ComfyUI-ZML-Image in ComfyUI Manager, then restart. No models, no extra downloads.
Two things to keep in mind. First, 无固定形状 needs a real alpha channel to detect the outline - a JPG with no transparency will just behave like the rectangle mode. Second, the transparent-background conversion only works if the input actually has transparency to convert; if your image is already opaque, nothing changes and that's correct behavior, not a bug. The node's Chinese-only UI might trip you up for the first five minutes, so grab the English translation patch from github.com/zml-w/ZZZ_ZML_English_Patch while you're at it. This is a one-person pack with no real English community, so when something confuses you, the GitHub issues tab is where the author actually responds.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| 图像 | IMAGE | — | |
| 处理模式 | COMBO | 3 options: 矩形, 无固定形状, 透明转纯色 | |
| 背景颜色 | COMBO | 4 options: 白色, 黑色, 绿色, 透明 | |
| 外拓像素 | INT | 500–1024 | — |
| 外拓方向 | COMBO | 7 options: 全方向, 上, 下, 左, 右, 上下, +1 |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| 图像 | IMAGE | — |