Nodes/ComfyUI-ImgMask2PNG/🌊ImageMask2PNG
ComfyUI Node

🌊ImageMask2PNG

Turn a mask into real transparency — the one-node glue for cutouts

By freelifehacker·Created 2 years ago·Updated 2 years ago· 0
🌊ImageMask2PNG
  • mask
  • image
  • image

You've got a mask, you've got an image, and what you actually want is a transparent PNG you can drop onto another scene. That's the whole job of ImageMask2PNG: it takes an IMAGE and a MASK and returns the image with the mask burned into its alpha channel. White in the mask means opaque, black means fully transparent, and everything between becomes soft alpha. It's not a background remover - it's the two-second step after the background remover, the glue that turns a segmentation result into a real cutout you can save.

It matters more than its size suggests because of a ComfyUI quirk: plenty of nodes silently drop or ignore the alpha channel, and there's no single core node that just says "make this mask the alpha." Normally you'd hack it together with composite and colorize nodes. This one node is that pattern, pre-assembled.

How it works. For each image/mask pair in the batch it converts both to PIL, then does exactly three things: resizes the mask to the image's dimensions if they don't match (LANCZOS, and it prints a notice when it has to), converts the mask to grayscale, and pastes the RGBA image onto a blank layer using that grayscale mask as the paste mask. That paste mask is the alpha channel - nothing is generated or inferred, the mask values just become opacity. Output is a four-channel IMAGE tensor, so wire it straight into a Save Image node set to PNG (JPEG will silently flatten your alpha to black).

The inputs that matter - all two of them. mask (MASK) and image (IMAGE), both required, and both batched together. There are no knobs, no settings, no modes. Either the mask already matches your image, or the node quietly resizes it for you. The single output is image.

Where it slots into a real workflow. ComfyUI has shipped BiRefNet in core since May 2026, and that's the classic pairing: image → BiRefNet → mask → this node → Save Image, and you've got a transparent layer ready to composite. Same shape works with SAM or rembg masks, and with masks you drew or inpainted by hand when you specifically want a region to become real transparency instead of just a selection. Because it resizes the mask for you, it also tolerates that classic mismatch where your mask came out at a different resolution than the source.

Install. No models, no requirements.txt, nothing heavy - the whole pack is one Python file using only PIL, torch and numpy, which ComfyUI already ships. Grab it via ComfyUI Manager (search "ComfyUI-ImgMask2PNG") or:

cd ComfyUI/custom_nodes
git clone https://github.com/freelifehacker/ComfyUI-ImgMask2PNG

then restart ComfyUI.

Gotchas worth knowing. First, the alpha is a straight copy of the mask - so a soft, feathered mask gives you semi-transparency everywhere, not a crisp cutout. If you wanted a hard edge, threshold the mask before feeding it in. Second, a mask used for selection inpainting usually has no alpha intent at all; don't be surprised when the "transparent" result looks like a photo with a hole. Third, remember the mask is a source, not a request - if the mask misses hair or a wisp, no node can fix that; pick a better segmentation model, not a better glue. And the README is a single Chinese line, so treat the code as the docs.

Category🌊ImageMask2PNG

Inputs (2)

NameTypeDefaultDescription
maskMASK
imageIMAGE

Outputs (1)

NameTypeDescription
imageIMAGE