3

Is there a way to find out the number of layers there are in a .psd?

I have .psds that are slowing down terribly. There are 20-30 layer comps and an unknown amount of layers. 1000? 5,0000? I don't know.

The reason for this is to start to ascertain at what point photoshop starts to choke. If I have photoshop use 90 of available memory it quickly hogs up 11GB slowing down my box for other purposes and if I leave it at 50% (7GB) there is a pause when I duplicate even the smallest layer (say a checkmark that goes into a checkbox).

0

6 Answers 6

5

You could use python psdtools package for this:

from __future__ import print_function
from psd_tools import PSDImage

psd = PSDImage.load('my_image.psd')
print("file has {} layers".format(len(psd.layers)))
1
  • I'm having trouble downloading this package at work. I'm not getting admin access to download psdtools (or 7-zip). Will check it out at home.
    – Mayo
    Nov 4, 2015 at 15:08
2

Do the following:

  1. From the status bar on the bottom left corner of the editing window, click on the right-pointing arrow.

Editing windows with status bar: The right-pointing arrow is highlighted.

  1. From the popup menu that appears, select "Layer Count".
  2. Read the number of layers on the status bar.

The status bar reads: 108 layers, 18 groups

2
  • 1
    @FleetCommand, thanks for demonstrating how to write a good answer.
    – fixer1234
    Jan 10, 2017 at 17:11
  • @Burgi Yes, i know, but i was kinda amazed by the complicated coding and stuff versus a 2 clicks solutions (compensated with pictures tho)
    – Goosfraba
    Jan 20, 2017 at 1:41
1

Just a thought: If you're on a Mac, the Finder's file info (cmd-i) might be helpful, as it lists all names of the layers without even opening the file . You could copy this into a text editor with line numbering and replace all commas with linefeeds. The line numbering would reveal the number of layers (I havn't tested what happens with commas in layer names).

EDIT:

One more finding: Gimp has an info panel that shows the layer count for a psd file (Menu: Image > Image Properties)

gimp psd layercount

3
  • Interesting. Unfortunately I'm not on a mac. I did see that when I googled. I didn't see that option for a PC.
    – Mayo
    Nov 3, 2015 at 18:42
  • maybe this helps, on a quick glance it didn't look mac specific: blog.kyletunneyphotography.com/counting-layers-in-photoshop
    – AAGD
    Nov 3, 2015 at 19:20
  • thx. I saw that while searching (after posting) and I see that Rishab Ag copied and pasted the text from that site. Will try it out.
    – Mayo
    Nov 3, 2015 at 19:26
0

Unfortunately there is no automatic feature to count the layer but here you can use this script-

var totalProgress = 0// I assume this is defined eleswhere but is needed for the scriptler
function layerCounter(inObj)  // recursive function to count layers
{
    totalProgress+= inObj.artLayers.length;       
    for( var i = 0; i < inObj.layerSets.length; i++) {
        totalProgress++;
      layerCounter(inObj.layerSets[i]);  // recursive call to layerCounter
    }
   return totalProgress;
}

function getLayerCount(){
   function getNumberLayers(){
   var ref = new ActionReference();
   ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID("NmbL") )
   ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
   return executeActionGet(ref).getInteger(charIDToTypeID("NmbL"));
   }

   function getLayerType(idx) {
       var ref = new ActionReference();
       ref.putProperty( charIDToTypeID("Prpr") , stringIDToTypeID("layerSection"));
       ref.putIndex(charIDToTypeID( "Lyr " ), idx);
       return typeIDToStringID(executeActionGet(ref).getEnumerationValue(stringIDToTypeID('layerSection')));
   };
   var cnt = getNumberLayers();
   var res = cnt;
   if(activeDocument.layers[activeDocument.layers.length-1].isBackgroundLayer){
         var i = 0;
         //comment out line below to exclude background from count
         res++;
      }else{
         var i = 1;
      }; 
   for(i;i<cnt;i++){
      var temp = getLayerType(i);
      if(temp == "layerSectionEnd") res--;
      //if(temp == '"layerSectionStart") res--;//uncomment to count just artLayers
   };
   return res;
};

function main()
{
   var answer = confirm("Go through your file and count all the layers??");
   if(answer) {
      var reporter1 = layerCounter(app.activeDocument);
      alert("Kyletunney.com - All done! Layer count = " + reporter1);
   } else {
      reporter2 = getLayerCount();
      alert("Kyletunney.com - All done! Layer count = " + reporter2);

   }   
}

main();

Save the script as .jsx

How to use the script?

  • Open up Photoshop with the file you wish to count
  • Click on ‘File’
  • Then ‘Scripts’
  • Now click ‘Browse’
  • Find the script you just saved and click Load
  • You will now be prompted with ‘Go through your file and count all the layers??‘ Click ‘Yes’
  • You will now be informed of the amount of layers in your file!
2
  • I tried this script twice. It crashed Photoshop both times. Maybe it works with a file with 10 layers. But it hasn't worked on a file with hundreds. Or is it thousands?
    – Mayo
    Nov 4, 2015 at 14:48
  • strangely this scripts reports 48 layers on a file that has 38 layers.. :(
    – Duck
    Jul 14, 2016 at 19:54
0

Ok, this may sound silly simple (if you have Photoshop), but the easiest way is to open the document in Photoshop and click the New Layer button at the bottom of the layers panel. The new layer will automatically be named "Layer 450" or one more than the number of the layers currently in the document.

0

If you are using a Mac, run this script on Script Editor:

tell application "Adobe Photoshop CC 2015.5"
    activate
    set theDOC to the current document
    tell theDOC
        set numberOfLayers to count of layers
        display dialog numberOfLayers as string
    end tell
end tell

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .