Nodes/KJNodes for ComfyUI/Save Image With Alpha
ComfyUI Node Runs on cloud

Save Image With Alpha

Write a transparent PNG from an image plus a mask

By kijai·Created 3 years ago·Updated 8 days ago· 3,165
Save Image With Alpha
  • images
  • mask
    filename_prefixComfyUI

    The stock ComfyUI SaveImage node flattens everything to an opaque RGB PNG. That's fine until you've spent a whole graph cutting a subject out of its background and you want to keep that transparency in the saved file. This node does exactly and only that: it takes an image and a mask and writes a PNG with the mask baked in as the alpha channel. Transparent-background cutouts, straight to disk.

    Why you'd use it

    In ComfyUI, images and their transparency live in separate lanes - an IMAGE carries the RGB pixels, a MASK carries the coverage. Background-removal nodes (RMBG, BiRefNet, SAM, whatever you use) hand you the subject as an image plus a mask marking what's foreground. To turn that into an actual usable transparent PNG - the kind you drop into a compositing app, a thumbnail, a sticker, a product shot - something has to weld the mask onto the image as alpha. That's this node's entire reason to exist.

    It's an output node, so it sits at the very end of the chain and it's what triggers the save. There's no output socket to wire onward; it writes the file and that's the terminus.

    The inputs that matter

    Three, and there's nothing hidden:

    • images - the RGB image(s) you're saving.
    • mask - the alpha. White stays opaque, black goes transparent, greys become partial transparency. This is usually the mask straight out of your background remover; if your remover gives you foreground-as-white, it drops in as-is.
    • filename_prefix (default ComfyUI) - the name stem for the saved file, same convention as the native SaveImage node. Set it to something you'll actually find later.

    Because it saves a real 4-channel PNG, semi-transparent edges - hair, motion blur, soft shadows - are preserved as partial alpha rather than a hard cut, which is what makes the result look composited rather than stamped.

    How to install it

    It's part of kijai's KJNodes pack.

    • ComfyUI Manager - search KJNodes for ComfyUI, install, restart.
    • Manual - cd ComfyUI/custom_nodes && git clone https://github.com/kijai/ComfyUI-KJNodes, then pip install -r ComfyUI-KJNodes/requirements.txt, restart.

    Nothing to download. It's a thin wrapper over PNG saving.

    Common issues & troubleshooting

    The saved PNG has no transparency. The mask is the alpha - if it's fully white (everything opaque) you get an opaque image, which is correct behavior for that input. Check what your background-removal node is actually feeding in; if it hands you the background as white instead of the foreground, invert the mask first.

    The transparency is backwards - subject vanished, background kept. Same root cause, opposite direction: your mask polarity is flipped. Drop an InvertMask (or the KJNodes equivalent) before this node.

    Edges look like a hard cutout. That's the mask being hard-edged, not the node. If you want soft hair and clean edges, blur or feather the mask a touch before saving - the node faithfully writes whatever alpha you give it, crisp or soft.

    You wanted the alpha in a JPEG. Can't - JPEG has no alpha channel. Transparency only survives in a format that supports it, which is why this node writes PNG. If you need a flat JPEG, that's the ordinary SaveImage node's job.

    CategoryKJNodes/image

    Inputs (3)

    NameTypeDefaultDescription
    imagesIMAGE
    maskMASK
    filename_prefixSTRINGComfyUI

    Outputs (0)

    No outputs