Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Trouble with photoshop layer masks

New Here ,
Jan 21, 2022 Jan 21, 2022

can someone please tell me how i can get photoshop to let me export layer masks as PNG files

TOPICS
Windows
3.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Community Expert , Jan 21, 2022 Jan 21, 2022

Alt + click on layer mask to show mask on screen. Ctrl + A to Select All, Ctrl + C to copy. Alt + click to exit layer mask, Ctrl + Shift + N to create new layer, Ctrl + V to paste copied content. Right click on layer with mask then Quick Export as PNG or Export As. Delete layer with mask (not layer mask but newly created) if you do not need it anymore. That is my suggestion and one possible way. I am assuming that layer with layer mask is top most layer in the Layers panel.

 

You can even automa

...
Translate
Community Expert , Jan 22, 2022 Jan 22, 2022

Another way:

When we select a layer mask it will appear as a new channel. We can right click that channel and choose Duplicate

image.png

When the Duplicate Channel window opens, use the drop down and select New You can then save the new document as a PNG

image.png

Just to be sure, do you want the PNG files to have transparency?

 

Translate
Adobe
Community Expert ,
Jan 21, 2022 Jan 21, 2022

Alt + click on layer mask to show mask on screen. Ctrl + A to Select All, Ctrl + C to copy. Alt + click to exit layer mask, Ctrl + Shift + N to create new layer, Ctrl + V to paste copied content. Right click on layer with mask then Quick Export as PNG or Export As. Delete layer with mask (not layer mask but newly created) if you do not need it anymore. That is my suggestion and one possible way. I am assuming that layer with layer mask is top most layer in the Layers panel.

 

You can even automate process if you are familiar with actions in Photoshop. Save for Web must be used for Export step, by the way.

automate export layer mask.jpg

 

If described is not what you exactly want, please explain further what is expected outcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 21, 2022 Jan 21, 2022
I finally figured it out. Thanks. I realised I had deleted the original
pixel layer I had copied from and just kept copying layer masks with hue
adjustments to each one. I ended up just duplicating the original pixel
layer and just used the effects on the pixel layer
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 22, 2022 Jan 22, 2022

 

@Bojan Živković â€“ I like this method, as it can retain the colour profile of the source document.

 

I also like the alternative method from @Trevor.Dennis as it is only a single channel, however that makes colour management harder (but not impossible).

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 22, 2022 Jan 22, 2022

Another way:

When we select a layer mask it will appear as a new channel. We can right click that channel and choose Duplicate

image.png

When the Duplicate Channel window opens, use the drop down and select New You can then save the new document as a PNG

image.png

Just to be sure, do you want the PNG files to have transparency?

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 22, 2022 Jan 22, 2022

The following script is simple, more could be done, but this is a good start. The active layer's raster layer mask will be saved as a grayscale mode PNG using the active document's name and the layer mask name with a space/hyphen/space separator.

 

The script only considers pixel layer masks, not vector (vector mask support could be added).

 

Example output filename: My Document - Layer 1 Mask.png

 

Edit: Original script code updated to version 1.1

 

/*
Active Layer Mask to PNG.jsx

https://community.adobe.com/t5/photoshop-ecosystem-discussions/trouble-with-photoshop-layer-masks/td-p/12698065

Stephen Marsh, 23rd January 2022 - v1.1

Note: 
The script is simple - the saved PNG is grayscale mode and is not colour
managed. There is no error checking to ensure that there is an active
layer. If no layer is selected, the uppermost layer will be used (this
may not be expected). PNG files are saved to the active document path,
unsaved documents will have the PNG file saved to the desktop.
*/

#target photoshop

if (app.documents.length > 0) {

    // Raster mask, vector mask not currently supported
    if (hasLayerMask() === true) {

        try {
            // Use the previously saved path
            //var docPath = decodeURI(app.activeDocument.path);
            var docPath = app.activeDocument.path.fsName;
        } catch (e) {
            // If unsaved, select the desktop
            var docPath = "~/Desktop";
        }

        // FileName + LayerName + Mask
        var maskDocName = app.activeDocument.name.replace(/\.[^\.]+$/, '') + " - " + app.activeDocument.activeLayer.name + " Mask";

        // Select active layer mask channel
        selectLayerMask(false);

        // Dupe active channel to new doc
        dupeChannel(maskDocName, "currentChannelName");

        // Convert from multichannel mode to something supported by PNG
        app.activeDocument.changeMode(ChangeMode.GRAYSCALE);

        // Save as PNG options
        var pngFile = new File(docPath + "/" + maskDocName + ".png");
        if (pngFile.exists) {
            // true = 'No' as default active button
            if (!confirm('File "' + maskDocName + ".png" + '" exists, overwrite: Yes or No?', true))
                //throw null;
                throw app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
        }
        var pngOptions = new PNGSaveOptions();
        pngOptions.compression = 0;
        pngOptions.interlaced = false;
        app.activeDocument.saveAs(pngFile, pngOptions, true, Extension.LOWERCASE);
        app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
        app.beep();
        alert("Layer mask saved to PNG:" + "\r" + docPath + "/" + maskDocName + ".png");

    } else {
        alert("There is no layer mask!");
    }

} else {
    alert("You must have a document open!");
}

// Functions

function selectLayerMask(makeVisible) {
	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	}
	var descriptor = new ActionDescriptor();
	var reference = new ActionReference();
	reference.putEnumerated(s2t("channel"), s2t("channel"), s2t("mask"));
	descriptor.putReference(s2t("null"), reference);
	descriptor.putBoolean(s2t("makeVisible"), makeVisible);
	executeAction(s2t("select"), descriptor, DialogModes.NO);
}

function dupeChannel(name2, channelName) {
var s2t = function (s) {
    return app.stringIDToTypeID(s);
}
var descriptor = new ActionDescriptor();
var descriptor2 = new ActionDescriptor();
var reference = new ActionReference();
descriptor2.putString(s2t("name"), name2);
descriptor.putObject(s2t("new"), s2t("document"), descriptor2);
reference.putEnumerated(s2t("channel"), s2t("ordinal"), s2t("targetEnum"));
descriptor.putReference(s2t("using"), reference);
descriptor.putString(s2t("channelName"), channelName);
executeAction(s2t("make"), descriptor, DialogModes.NO);
}

function hasLayerMask() {
    // From Adobe's Flatten All Masks.jsx
    var hasLayerMask = false;
    try {
        var ref = new ActionReference();
        var keyUserMaskEnabled = app.charIDToTypeID('UsrM');
        ref.putProperty(app.charIDToTypeID('Prpr'), keyUserMaskEnabled);
        ref.putEnumerated(app.charIDToTypeID('Lyr '), app.charIDToTypeID('Ordn'), app.charIDToTypeID('Trgt'));
        var desc = executeActionGet(ref);
        if (desc.hasKey(keyUserMaskEnabled)) {
            hasLayerMask = true;
        }
    } catch (e) {
        hasLayerMask = false;
    }
    return hasLayerMask;
}
 
Apart from adding error checking for an active layer (which apparently is not so easy to do), this should probably suffice for a single layer. The script should save the mask from any layer kind that can contain a mask. Further code would be required to restrict to certain kinds of layers.
 
The next logical step is to automate saving the layer mask from every layer. This poses further questions – should this only be for layers, or layer sets or both? If layer sets, what about the contents of layer sets, whether they are nested layer sets or only layers?
 
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 22, 2022 Jan 22, 2022
LATEST

This script is an extension of the previous script, it will save all selected top level layer's raster masks to PNG for both selected layers and layer sets.

 

It has the same limitations/conditions as the Active Layer Mask to PNG.jsx script above.

 

/*
Selected Layers Masks to PNG.jsx

https://community.adobe.com/t5/photoshop-ecosystem-discussions/trouble-with-photoshop-layer-masks/td-p/12698065

Stephen Marsh, 23rd January 2022 - v1.0

Note: 
The script is simple - the saved PNG is grayscale mode and is not colour
managed. There is no error checking to ensure that there is an active
layer. If no layer is selected, the uppermost layer will be used (this
may not be expected). PNG files are saved to the active document path,
unsaved documents will have the PNG file saved to the desktop.
*/

#target photoshop

// Optionally select all layers, uncomment if reqiured
// app.runMenuItem(stringIDToTypeID('selectAllLayers'));

/***** Process Selected Layers from Jazz-y *****/
var s2t = stringIDToTypeID;
(r = new ActionReference).putProperty(s2t('property'), p = s2t('targetLayersIDs'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
var lrs = executeActionGet(r).getList(p),
    sel = new ActionReference();

for (var i = 0; i < lrs.count; i++) {
    sel.putIdentifier(s2t('layer'), p = lrs.getReference(i).getIdentifier(s2t('layerID')));
    (r = new ActionReference).putIdentifier(s2t('layer'), p);
    (d = new ActionDescriptor()).putReference(s2t("target"), r);
    executeAction(s2t('select'), d, DialogModes.NO);
/***** Process Selected Layers from Jazz-y *****/

    if (app.documents.length > 0) {
    
    // Raster mask, vector mask not currently supported
    if (hasLayerMask() === true) {

        try {
            // Use the previously saved path
            //var docPath = decodeURI(app.activeDocument.path);
            var docPath = app.activeDocument.path.fsName;
        } catch (e) {
            // If unsaved, select the desktop
            var docPath = "~/Desktop";
        }

        // FileName + LayerName + Mask
        var maskDocName = app.activeDocument.name.replace(/\.[^\.]+$/, '') + " - " + app.activeDocument.activeLayer.name + " Mask";

        // Select active layer mask channel
        selectLayerMask(false);

        // Dupe active channel to new doc
        dupeChannel(maskDocName, "currentChannelName");

        // Convert from multichannel mode to something supported by PNG
        app.activeDocument.changeMode(ChangeMode.GRAYSCALE);

        // Save as PNG options
        var pngFile = new File(docPath + "/" + maskDocName + ".png");
        if (pngFile.exists) {
            // true = 'No' as default active button
            if (!confirm('File "' + maskDocName + ".png" + '" exists, overwrite: Yes or No?', true))
                //throw null;
                throw app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
        }
        var pngOptions = new PNGSaveOptions();
        pngOptions.compression = 0;
        pngOptions.interlaced = false;
        app.activeDocument.saveAs(pngFile, pngOptions, true, Extension.LOWERCASE);
        app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

    }

    } else {
        alert("You must have a document open!");
    }
}

// End of script notification
app.beep();
alert("Selected layer masks saved to PNG at the following path:" + "\r" + docPath);


// Functions

function selectLayerMask(makeVisible) {
	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	}
	var descriptor = new ActionDescriptor();
	var reference = new ActionReference();
	reference.putEnumerated(s2t("channel"), s2t("channel"), s2t("mask"));
	descriptor.putReference(s2t("null"), reference);
	descriptor.putBoolean(s2t("makeVisible"), makeVisible);
	executeAction(s2t("select"), descriptor, DialogModes.NO);
}

function dupeChannel(name2, channelName) {
    var s2t = function (s) {
        return app.stringIDToTypeID(s);
    }
    var descriptor = new ActionDescriptor();
    var descriptor2 = new ActionDescriptor();
    var reference = new ActionReference();
    descriptor2.putString(s2t("name"), name2);
    descriptor.putObject(s2t("new"), s2t("document"), descriptor2);
    reference.putEnumerated(s2t("channel"), s2t("ordinal"), s2t("targetEnum"));
    descriptor.putReference(s2t("using"), reference);
    descriptor.putString(s2t("channelName"), channelName);
    executeAction(s2t("make"), descriptor, DialogModes.NO);
}

function hasLayerMask() {
    // From Adobe's Flatten All Masks.jsx
    var hasLayerMask = false;
    try {
        var ref = new ActionReference();
        var keyUserMaskEnabled = app.charIDToTypeID('UsrM');
        ref.putProperty(app.charIDToTypeID('Prpr'), keyUserMaskEnabled);
        ref.putEnumerated(app.charIDToTypeID('Lyr '), app.charIDToTypeID('Ordn'), app.charIDToTypeID('Trgt'));
        var desc = executeActionGet(ref);
        if (desc.hasKey(keyUserMaskEnabled)) {
            hasLayerMask = true;
        }
    } catch (e) {
        hasLayerMask = false;
    }
    return hasLayerMask;
}

 

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines