据我所知,你有一个photoshop文件。背景位于堆栈的底部。下一层,我们称它为第1层,然后是第2层等。层1 & 2需要合并和导出。然后需要合并和导出图层1,3。 你没有提到背景是否需要与它们合并。 无论如何,我正在假设图层需要与背景合并 - 如果不是这种情况,很容易改变。这里有一个脚本可以满足你的需求:
app.preferences.rulerUnits = Units.PIXELS;
// call the source document
var srcDoc = app.activeDocument;
fileName = app.activeDocument.name;
var myDocName = fileName.substring(0,fileName.length -4)
var numOfLayers = srcDoc.layers.length;
hideEverything(srcDoc)
processLayers (srcDoc)
function processLayers (sourceDocument)
{
for (var i = numOfLayers -1; i >= 0 ; i--)
{
srcDoc.activeLayer = srcDoc.artLayers[i];
thisLayer = srcDoc.artLayers[i].name;
// duplicate the document
var id17396 = charIDToTypeID("Dplc");
var desc3299 = new ActionDescriptor();
var id17397 = charIDToTypeID("null");
var ref2177 = new ActionReference();
var id17398 = charIDToTypeID("Dcmn");
var id17399 = charIDToTypeID("Ordn");
var id17400 = charIDToTypeID("Frst");
ref2177.putEnumerated(id17398, id17399, id17400);
desc3299.putReference(id17397, ref2177);
var id17401 = charIDToTypeID("Nm ");
desc3299.putString(id17401, thisLayer); //change the name of the document
executeAction(id17396, desc3299, DialogModes.NO);
// Flatten the image
app.activeDocument.flatten();
// Set myFilePath and fileName to source path
myFilePath = srcDoc.path + '/' + app.activeDocument.name +'.png';
try
{
// save out the image
var pngFile = new File(myFilePath);
pngSaveOptions = new PNGSaveOptions();
pngSaveOptions.embedColorProfile = true;
pngSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
pngSaveOptions.matte = MatteType.NONE; pngSaveOptions.quality = 1;
activeDocument.saveAs(pngFile, pngSaveOptions, false, Extension.LOWERCASE);
}
catch(e)
{
alert(e)
}
// close that saved png
app.activeDocument.close()
// select the document that's been open the longest
app.activeDocument = srcDoc;
}
}
function hideEverything(sourceDocument)
{
for (var i = numOfLayers -2; i >= 0 ; i--) // don't include background
{
srcDoc.artLayers[i].visible = false;
}
}
谢谢你的脚本。最底层是作为背景。我会测试脚本并让你知道它是如何工作的。 – adam
我可以确认这个脚本很好用。非常感谢你。 – adam