2012-11-20 127 views
1

嗨,我有一個非常具體的問題需要解決。Photoshop通過合併下一層將圖層導出爲PNG

我有不同層數的Photoshop文件。可以說,其中一個有10層 不,我需要導出每一層,但在此爲 最底層是第一個文件。 然後,我需要導出第一個和第二個合併(第一個圖層上方的所有圖層都將混合模式設置爲屏幕),接下來的前三個合併,然後是四個等等。

我不知道Photoshop中的腳本,在Google中找不到任何東西。 任何幫助,將不勝感激。 我使用Photoshop CS5

回答

1

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

謝謝你的腳本。最底層是作爲背景。我會測試腳本並讓你知道它是如何工作的。 – adam

+0

我可以確認這個腳本很好用。非常感謝你。 – adam

相關問題