Transparent PNG From Mask
A mask isn't transparency — this node is the bridge
- image
- mask
- image
- mask
Here's the thing everyone learns the hard way: having a mask is not the same as having transparency. ComfyUI will happily give you a perfect cutout mask from BiRefNet, SAM, or your own hand-drawn scribble - and then every downstream node treats your "transparent" PNG as an opaque one, because nothing ever turned that mask into an alpha channel. Transparent PNG From Mask is the little two-wire bridge that does exactly that conversion. You feed it an image and a mask; it hands back a real RGBA image where the masked area stays opaque and everything else is transparent.
It's a plumbing node, not a magic one. It won't remove your background for you - the mask has to already exist. Where it shines is at the end of a chain: segmentation node → mask → here → Save Image, and suddenly your sprite, product shot, or icon is a genuine transparent PNG you can drop into a game engine or composite onto anything.
How it works
Mechanically this is one of the most transparent nodes you'll ever open. It takes the RGB channels from your image, adds your mask as the fourth channel, and concatenates them into [B, H, W, 4]. Mask value becomes alpha, plain and simple - no dithering, no guessing, nothing hidden. That also means a hard binary mask gives you a hard binary edge. If you want soft, feathered cutout edges, blur the mask before it gets here (a Mask Blur node will do); the node itself won't soften anything for you.
It also does the boring-but-important housekeeping around that core swap: matching image and mask sizes when they disagree, optionally inverting the mask, and optionally trimming.
The inputs that matter
You'll set most of these once and never think about them again, but three deserve a look:
- image and mask - the two required wires. Image can be RGB or RGBA (an existing alpha channel is ignored, which is fine). The mask defines what stays opaque.
- trim_to_mask (default off) - crops both the output image and mask to the bounding box of the mask, so your transparent PNG is tightly cropped to the subject. Great for sprites or asset packs where you don't want miles of empty transparent canvas. padding (default 10px) adds breathing room around that box, clamped to the image bounds.
- invert_mask - flips which side is opaque. Handy if your segmentation output is foreground/background backwards.
resize_mode is where a beginner can get tripped up. The three choices are scale_mask_to_image (default), scale_image_to_mask, and none. Here's the trap: none does not mean "no scaling." If the sizes genuinely mismatch, it prints a warning and silently scales the mask to fit anyway, just to avoid crashing your graph. You can't actually produce a mismatched output - the node always reconciles sizes, you only pick which side bends.
Two outputs come out: image (the RGBA tensor) and mask (the adjusted/cropped mask). Wire the image into a Save Image node and that's your transparent PNG. The mask output is mostly for when you trimmed, so downstream nodes see the same cropped region.
Installing it
Single-node pack, zero dependencies - it's pure torch, which ComfyUI already has, so there are no models to download and no requirements.txt battles. Easiest route is ComfyUI Manager: search "comfyui-transparent-png-creator" and hit install. Or, the manual way:
cd ComfyUI/custom_nodes
git clone https://github.com/CountlessSkies/comfyui-transparent-png-creator
Then restart ComfyUI and it shows up under the image/process category.
Gotchas worth knowing
- The empty-mask case doesn't crash - if your mask has no pixels above a faint noise threshold (0.05), the node returns a tiny 8x8 fully transparent image instead of exploding. Good behavior, but it means a silent failure: you get a transparent nothing. Check your mask actually has content.
- Do this last. Run it as close to the Save Image node as you can. Plenty of ComfyUI nodes silently drop an alpha channel as they pass tensors around - that's the classic reason your "transparent" image comes out black or opaque. Build your RGBA right before saving and the graph can't eat it on the way out.
- This is the same job LayerDiffusion does natively by generating RGBA during diffusion - but that tooling stalled and never reached Flux. Until that changes, mask-then-bridge is the reliable route, and it works with any checkpoint, any image, any source.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| mask | MASK | — | |
| trim_to_mask | BOOLEAN | false | — |
| padding | INT | 100–1000 | — |
| invert_mask | BOOLEAN | false | — |
| resize_mode | COMBO | scale_mask_to_image | 3 options: scale_mask_to_image, scale_image_to_mask, none |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |