Fill Alpha
Flatten a transparent PNG onto a solid color — Fill Alpha kills the alpha channel
- image
- image
Transparent PNGs are great until whatever you're feeding them into refuses to accept alpha - then you're stuck compositing onto a background by hand. Fill Alpha is that flattening step, automated. It takes an RGBA image, replaces the transparent pixels with a solid RGB color you choose, and hands back a clean three-channel image with no alpha channel left to argue about.
The name is slightly backwards from what you might expect: it doesn't "fill alpha" by adding an alpha channel - it fills behind the alpha and then drops the alpha entirely. The result is a plain RGB image you can feed into anything that chokes on transparency.
The mechanism, from the source, is per-pixel and simple. The node requires an RGBA input - it literally raises an exception if the image mode isn't RGBA - then walks every pixel and applies one rule:
- If the pixel's alpha is below
alpha_threshold, it's replaced with your fill color(r, g, b). - If the alpha is at or above the threshold, the pixel is kept, but its RGB is premultiplied by the alpha value (
r * a / 255), which darkens semi-transparent edge pixels appropriately instead of leaving a hard fringe.
That premultiplication is the bit that separates this from a dumb threshold fill - feathered edges blend into your background color instead of leaving a halo.
The inputs that matter:
- image - your RGBA image.
- alpha_threshold - the cutoff, default
128. Pixels below this alpha count as "transparent." - r, g, b - the fill color, defaults
0, 128, 0- yes, that's green, which is an odd default but trivially changed.
The output:
- image - the flattened RGB result.
Where you'd use it: exported game sprites, rendered cutouts, or any pipeline that needs a transparent asset composited onto a known background before save or further processing. In the FairLab pack it's the sibling of Image Remove Alpha, which does a similar flatten using a mask and a hex color - Fill Alpha is the version that reads the alpha directly from the image itself. Pick based on whether your transparency lives in the image's own alpha channel (this node) or in a separate mask (Image Remove Alpha).
Honest gotchas: because it iterates every pixel in Python, big images are slow - a 2048² RGBA image is four million pixels of per-pixel work, so don't put this on a hot path in a batch loop. And the RGBA requirement means an RGB image fed straight in will throw; convert first if needed.
Install is the standard pack path: ComfyUI Manager → search ComfyUI-FairLab → install → restart:
cd ComfyUI/custom_nodes
git clone https://github.com/yanhuifair/ComfyUI-FairLab.git
cd ComfyUI-FairLab
pip install -r requirements.txt
Restart, search "Fill Alpha". No models, no heavy deps - just Pillow.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| alpha_threshold | INT | 128 | — |
| r | INT | 0 | — |
| g | INT | 128 | — |
| b | INT | 0 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |