Nodes/TrentNodes/PSD Layer Flatten (RGBA)
ComfyUI Node

PSD Layer Flatten (RGBA)

The Flatten Node That Speaks Standard ComfyUI Mask

By TrentHunter82·Created 9 months ago·Updated 4 days ago· 36
PSD Layer Flatten (RGBA)
    • image
    • mask
    folder_path
    start_index0
    end_index0
    background_colortransparent
    respect_visibilitytrue

    Flattening a range of PSD layers into one image is a one-line ask, but the mask that comes with it can silently wreck a workflow if it uses the wrong polarity. This variant exists so you don't have to think about that: it outputs the flattened composite and a mask in the standard ComfyUI convention - white = opaque, black = transparent - ready to feed into inpainting, compositing, or any generic mask consumer.

    What it is

    Same inputs as its sibling PSD Layer Flatten: folder_path (a splitter output folder), start_index / end_index (inclusive range, 0 = bottom - wire them from PSDBackgroundDetect's bg_start/bg_end), background_color (transparent / white / black / hex), and respect_visibility (default on, skips hidden layers). The outputs are the flattened image as a 4-channel RGBA tensor with alpha preserved, plus mask in the standard white-opaque convention.

    Why there are two of these

    The pack's own splitter and loader emit masks the Photoshop way - inverted, white = transparent - because that's how alpha reads when you're reconstructing a stack. That convention is wrong for most of ComfyUI, which expects white to mean "this region is selected/opaque." So the pack ships two flattens that do the same rasterization but hand you masks in opposite polarities. If your mask is heading into an inpainting node, a SAM-driven process, or any standard mask input, use this one. If you're staying inside the pack's own convention for everything downstream, the non-RGBA variant keeps you consistent.

    It's a small thing, but it's exactly the kind of small thing that turns a 10-minute workflow into an hour of "why is everything inverted."

    When you'd reach for it

    The classic path: PSDBackgroundDetect returns a range → this node flattens just the background layers into one image → you run that through a background-removal or image-editing pass → then recomposite. Because the flattened output is a single RGBA image with a standards-compliant mask, it slots into ComfyUI's normal image/mask tooling without adapter nodes.

    Installing it

    Part of TrentNodes; one install serves the whole pack:

    cd ComfyUI/custom_nodes
    git clone https://github.com/TrentHunter82/TrentNodes.git
    cd TrentNodes
    pip install -r requirements.txt
    

    ComfyUI Manager ("Trent Nodes") works too, with the standing caveat: the author's day-one repo rename left two registry entries, and Manager occasionally flags the pack as "unsafe" - clone manually if it refuses. It reads the splitter's folder; no models, no downloads.

    The one thing to remember

    If your flattened image looks right but everything downstream is backwards, check whether you grabbed this variant or the other one. The image outputs match; the masks don't. That's the entire difference, and it's also the entire point.

    CategoryTrent/PSD

    Inputs (5)

    NameTypeDefaultDescription
    folder_pathSTRINGFolder from PSDLayerSplitter (must contain _manifest.json)
    start_indexINT00–9999First layer index to include (0 = bottom). Wire from PSDBackgroundDetect bg_start.
    end_indexINT00–9999Last layer index to include (inclusive). Wire from PSDBackgroundDetect bg_end.
    background_colorSTRINGtransparentCanvas backdrop: 'transparent', 'white', 'black', or hex like '#FFFFFF'
    respect_visibilityBOOLEANtrueIf True, skip layers marked hidden in the original PSD

    Outputs (2)

    NameTypeDescription
    imageIMAGEFlattened RGBA composite of the selected layers (4-channel, alpha preserved)
    maskMASKAlpha mask using standard ComfyUI convention: white = opaque/selected, black = transparent