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)))
Есть ли способ узнать количество слоев в .psd?
У меня есть .psds, которые ужасно замедляются. Есть 20-30 слоев и неизвестное количество слоев. 1000? 5,0000? Я не знаю.
Причина этого заключается в том, чтобы начать выяснять, в какой момент фотошоп начинает задыхаться. Если у меня есть фотошоп, использующий 90 доступной памяти, он быстро увеличивает 11 ГБ, замедляя мой блок для других целей, и если я оставляю его на 50% (7 ГБ), возникает пауза, когда я дублирую даже самый маленький слой (скажем, галочка, которая идет в флажок).
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)))
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
)
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?
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.
Если вы используете Mac, запустите этот скрипт в редакторе скриптов:
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
Сделайте следующее: