2012-11-20 125 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

相关问题