Copy link to clipboard
Copied
can someone please tell me how i can get photoshop to let me export layer masks as PNG files
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
...Another way:
When we select a layer mask it will appear as a new channel. We can right click that channel and choose Duplicate
When the Duplicate Channel window opens, use the drop down and select New You can then save the new document as a PNG
Just to be sure, do you want the PNG files to have transparency?
Copy link to clipboard
Copied
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.
If described is not what you exactly want, please explain further what is expected outcome.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
@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).
Copy link to clipboard
Copied
Another way:
When we select a layer mask it will appear as a new channel. We can right click that channel and choose Duplicate
When the Duplicate Channel window opens, use the drop down and select New You can then save the new document as a PNG
Just to be sure, do you want the PNG files to have transparency?
Copy link to clipboard
Copied
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;
}
Copy link to clipboard
Copied
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
Find more inspiration, events, and resources on the new Adobe Community
Explore Now