Nodes/D2-SavePSD-ComfyUI/D2 Apply Alpha Channel
ComfyUI Node

D2 Apply Alpha Channel

Turn a mask into an alpha channel that survives the trip to Photoshop

By da2el-ai·Created about a year ago·Updated about a year ago· 8
D2 Apply Alpha Channel
  • image
  • mask
  • IMAGE
invert_maskfalse

ComfyUI masks are greyscale tensors with a very short shelf life. They live inside the graph, do their job - driving an inpaint, cutting out a background - and then they're gone, because the PNG you save has nowhere to put them. If your workflow ends in Photoshop, that's a real problem: the person on the other end gets a flattened cutout and has to redo the masking by hand.

D2 Apply Alpha Channel exists to fix exactly that. It takes a MASK and stamps it into the alpha channel of an IMAGE, producing a proper RGBA image that the sibling node D2 Save PSD can write into a layered PSD. It's the "apply" half of a small three-node pack by the Japanese developer da2el, first cut in April 2025; D2 Extract Alpha is the undo button. No API calls, no model files, no GPU work - this is a CPU-side utility that runs in milliseconds.

The mechanism is genuinely simple under the hood. Give it an IMAGE and a MASK, optionally tick invert_mask. The node works out what shape your mask is - a single 2D mask, a full batch, or something odd with extra channel dimensions - broadcasts it across the image batch, and resizes it to match the image if the dimensions disagree. Then it writes the mask values straight into channel 3 of the output. With invert_mask on it flips the values first, which swaps which side of the mask ends up transparent. That's the whole thing: only three inputs, and they're all inputs you'll actually touch.

  • image - your RGB (or already-RGBA) tensor
  • mask - the mask to bake in, any of the shapes ComfyUI usually produces
  • invert_mask - default off; turn it on if your mask has transparent and opaque backwards

The single output is an IMAGE, now 4-channel. Wire it into D2 Save PSD's images input and you're done - that's the workflow this node was built for, and honestly the only one you need.

One warning worth carrying from the background-removal side of our knowledge base: not all ComfyUI workflows keep an RGBA pipeline alive - some nodes silently drop the alpha channel. So the practical rule is to apply alpha late, right before the save node, and don't run the RGBA result through random processing nodes on the way. Attach Apply Alpha as close to the output as you can.

Install

Same for all three nodes in the pack. Via ComfyUI Manager (search "D2-SavePSD-ComfyUI"), or manually:

cd {ComfyUI}/custom_nodes
git clone https://github.com/da2el-ai/D2-SavePSD-ComfyUI.git

Then the step everyone skips: the pack ships an install.py instead of a requirements.txt, and the README is explicit that you must run it even after installing with Manager. On Windows: ..\..\venv\Scripts\activate then python install.py; on Linux just activate your env and run python install.py. It installs psd-tools (with --no-deps) and scikit-image. No models, no heavy deps.

Common issues

  • Mask size mismatch won't error. The node silently resizes with bilinear interpolation, which can soften a hard edge. If your mask must stay crisp, match its resolution to the image upstream.
  • Fully transparent or fully opaque when you expected the opposite? That's invert_mask - flip it.
  • Batch behavior: a single 2D mask is broadcast to every frame in the batch. Great when all frames share one mask, a silent bug when they don't. If each frame needs its own alpha, feed it per-image masks.
CategoryD2/Image

Inputs (3)

NameTypeDefaultDescription
imageIMAGE
maskMASK
invert_maskBOOLEANfalse

Outputs (1)

NameTypeDescription
IMAGEIMAGE