Photoshop脚本隐藏并保存级别名称

时间:2013-11-28 14:10:46

标签: photoshop

我有一个大约200个级别的Photoshop文件,我需要为每个级别的网页保存,其中级别的名称隐藏其他级别...有没有办法用脚本执行此操作? 感谢

1 个答案:

答案 0 :(得分:1)

这会将每个图层保存为jpeg,以图层名称命名。你不需要随意隐藏图层;而是将每个图层复制为新图像,展平,保存然后关闭。不适用于任何团体(通常你必须支付额外的费用;))

var srcDoc = app.activeDocument;
var numOfLayers = srcDoc.layers.length;
var jpegQuality = 12;

for (var i = numOfLayers -1; i >= 0  ; i--)
{
  var theLayerName = srcDoc.layers[i].name;
  var theFile = srcDoc.path;
  srcDoc.activeLayer = srcDoc.artLayers[i];
  var id2784 = charIDToTypeID( "Mk  " );
  var desc707 = new ActionDescriptor();
  var id2785 = charIDToTypeID( "null" );
  var ref508 = new ActionReference();
  var id2786 = charIDToTypeID( "Dcmn" );
  ref508.putClass( id2786 );
  desc707.putReference( id2785, ref508 );
  var id2787 = charIDToTypeID( "Nm  " );
  desc707.putString( id2787, theLayerName );
  var id2788 = charIDToTypeID( "Usng" );
  var ref509 = new ActionReference();
  var id2789 = charIDToTypeID( "Lyr " );
  var id2790 = charIDToTypeID( "Ordn" );
  var id2791 = charIDToTypeID( "Trgt" );
  ref509.putEnumerated( id2789, id2790, id2791 );
  desc707.putReference( id2788, ref509 );
  executeAction( id2784, desc707, DialogModes.NO );
  app.activeDocument.flatten();
  SaveForWeb(theFile, jpegQuality);
  app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
  app.activeDocument = srcDoc;
}

function SaveForWeb(saveFile, jquality)
{
  var sfwOptions = new ExportOptionsSaveForWeb(); 
  sfwOptions.format = SaveDocumentType.JPEG; 
  sfwOptions.includeProfile = false; 
  sfwOptions.interlaced = 0; 
  sfwOptions.optimized = true; 
  sfwOptions.quality = jquality; 
  activeDocument.exportDocument(saveFile, ExportType.SAVEFORWEB, sfwOptions);
}