Photoshop CS6是否将嵌套图层导出到PNG? [英] Photoshop CS6 Export Nested Layers to PNG?

查看:175
本文介绍了Photoshop CS6是否将嵌套图层导出到PNG?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含100层图层的PSD.大多数都按组中的单个元素分组(嵌套).

I have a PSD that contains 100s of layers. Most are grouped with individual elements within the groups (nested).

如何将某些单个组(其中包含嵌套层)导出到PNG?

How do I Export to PNG certain individual groups (with nested layers inside of them)?

我不想运行将所有图层导出到PNG脚本",只需要将单个嵌套组(图层)导出到PNG.我发现了其他一些第三方脚本,但是它们可以导出所有内容.只需导出我选择的内容即可.

I don't want to run the Export All Layers to PNG Script, just need to export individual nested groups (layers) to PNG. I've found a few other 3rd party scripts, but they export everything. Only need to export the ones I've selected.

预先感谢

推荐答案

此脚本应执行您想要的操作.仅当您有要选择的组(不是该组中的某个层)时,它才有效.我没有对其进行广泛的测试,并且我假设您组中没有组(这很令人头疼)

This script should do what you want. It works only when you have the group that you want selected (not a layer within that group) I've not extensively tested it and I'm assuming you don't have groups within groups (which becomes a headache)

// export png from group
srcDoc = app.activeDocument;
var allLayers = new Array();
var selectedLayer = srcDoc.activeLayer;
var theLayers = collectAllLayers(app.activeDocument, 0);
var groupName = "";

// function collect all layers
function collectAllLayers (theParent, level)
{
  for (var m = theParent.layers.length - 1; m >= 0; m--)
  {
    var theLayer = theParent.layers[m];

    // apply the function to layersets;
    if (theLayer.typename == "LayerSet")
    {
      var goCode = false;
      allLayers.push(level + theLayer.name);
      groupName = theLayer.name
      // alert(level + " " + theLayer.name)
      collectAllLayers(theLayer, level + 1)


          var subDoc = srcDoc.layers[m];
          //alert(subDoc)
          var numOfSubLayers = subDoc.layers.length;

          //alert(numOfSubLayers)
          for (var j = numOfSubLayers -1; j >= 0 ; j--)
          {

            if (subDoc.layers[j].typename == "ArtLayer")
            {
              // if the selected (active) layer is in the group
              if (theLayer == selectedLayer)
              {
                var mylayerName = subDoc.layers[j].name
                srcDoc.activeLayer = subDoc.layers[j];
                // alert("Selected: " + mylayerName + " in " + groupName)
                processLayer(mylayerName)
                //selectAllLayersInGroup(groupName)
              }
            }
          }
    }
  }
}



function processLayer(alayername)
{
  // duplicate image into new document
  // =======================================================
  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, alayername );
  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 );

  // create new layer
  var layerRef = app.activeDocument.artLayers.add()
  layerRef.name = "temp"
  layerRef.blendMode = BlendMode.NORMAL

  //merge visible
  // =======================================================
  var id1435 = charIDToTypeID( "MrgV" );
  executeAction( id1435, undefined, DialogModes.NO );

  // Set filePath and fileName to source path
  filePath = srcDoc.path + '/' + app.activeDocument.name + '.png';

  // save out the image
  var pngFile = new File(filePath);
  pngSaveOptions = new PNGSaveOptions();
  pngSaveOptions.embedColorProfile = true;
  pngSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
  pngSaveOptions.matte = MatteType.NONE; pngSaveOptions.quality = 1;

  activeDocument.saveAs(pngFile, pngSaveOptions, false, Extension.LOWERCASE);

  // alert(filePath)
  // close that save png
  app.activeDocument.close()

  // selects document that's been open the longest
  app.activeDocument = srcDoc;
}

这篇关于Photoshop CS6是否将嵌套图层导出到PNG?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆