據我所知,你有一個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