News:

2023-03-15 Major improvements to the new Geolocation feature

Main Menu

Photoshop Layers Reported Directory Fashion

Started by Chris S, February 01, 2023, 02:02:41 PM

Previous topic - Next topic

Chris S

Is there a way with Exiftool to quickly get a list of Photoshop layers reported back in some type of return/directory fashion, as opposed to the reverse order, comma separated and </Layer group> designations? Am using this currently...

exiftool -LayerUnicodeNames [path_to_file]

Phil Harvey

I don't understand what you mean.  Currently I get something like this:

> exiftool -layerunicodenames test.psd
Layer Unicode Names             : Layer 3, Layer 2, Layer 1

What exactly is the format you would like to see?

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Chris S

In short, I'd be looking for a directory structure of the "rows" (groups=folders; layers=files).

This could possibly be with how -LayerUnicodeNames is reported, or in combination with another tag that identifies the type of row (group/layer) and level of indentation for that row. Would be OK to pull from the comma separated data that's reported now if there was a way to report via tag(s) so the folder/directory structure of the groups/layers could be recreated.

As reported now, you can see the layer/group (row) sequence from bottom-to-top properly, but using just -LayerUnicodeNames it's not readily available to discern the directory/folder parent/child structure properly. Not sure if the </Layer group> isn't reporting properly or if it wasn't designed to do that?

For example, in the attached, based how the rows are named you can see they are reporting in the correct (or at least reverse) sequence. However, without the layer/group naming for this example, you can't tell if the row is a group (folder) or layer, and therefore can't tell if the layers that follow them are parents, children, grand...

To illustrate this further looking at LayerExample.psd attached, the code doesn't tell you if the second row (02_Top-Group) that falls below the top row (01_Top-Layer) is a layer or group/folder, so you don't know when to start the group.

>exiftool -LayerUnicodeNames /Users/chrisswita/Desktop/LayerExample.psd
Layer Unicode Names             : 05_Bottom Layer, </Layer group>, 04.02_Sub-Layer_of_Bottom_Group, </Layer group>, 04.01.01_Sub-Layer_of_Sub-Group_of_Bottom_Group, 04.01_Sub-Group_of_Bottom_Group, 04_Bottom-Group, 03_Middle Layer, </Layer group>, 02.03_Bottom_Layer_of_Top_Group, </Layer group>, 02.02.01_Sub-Layer, 02.02_Sub-Group_of_Top-Group, 02.01_Sub-Layer_of_Top_Group, 02_Top-Group, 01_Top-Layer

Phil Harvey

#3
I understand now.  The sample was very helpful.

This was a fair bit of work for me to try to understand the Photoshop Layer structure, but I see a way to do what you want.

First, I'll have to extract the LayerSections information.  For your example file the LayerSections and LayerNames would be:

Layer Sections  : Layer, Divider, Layer, Divider, Layer, Folder (closed), Folder (open), Layer, Divider, Layer, Divider, Layer, Folder (open), Layer, Folder (open), Layer
Layer Names     : 05_Bottom Layer, </Layer group>, 04.02_Sub-Layer_of_Bottom_Group, </Layer group>, 04.01.01_Sub-Layer_of_Sub-Group, 04.01_Sub-Group_of_Bottom_Group, 04_Bottom-Group, 03_Middle Layer, </Layer group>, 02.03_Bottom_Layer_of_Top_Group, </Layer group>, 02.02.01_Sub-Layer, 02.02_Sub-Group_of_Top-Group, 02.01_Sub-Layer_of_Top_Group, 02_Top-Group, 01_Top-Layer

To reconstruct the layer hierarchy, you need to traverse these arrays in reverse order.  Each time you meet a "Folder" in the LayerSections you drop down a level, and each time you hit a "Divider" you pop back up a level.

Using these tags you could format the output however you like with a user-defined Composite tag.

I'll plan to add support for LayerSections in the next release.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Chris S

:o ! That would be way  8). Thank you!

2 more questions + 1 FYI on layers...

1) Assuming the -LayerSections would work for PSD, PSB and TIFF images (all created/saved from Photoshop) that have layers?

2) Is there a tag to identify the color (hex value) the layers are tagged with as well? I recall seeing something about this, but not sure if it was on this forum or reading through some Adobe tags documentation somewhere. Since you'll be extracting the -LayerNames and this likely follows the same structure as -LayerUnicode Names, would be cool if the Layer Tags/Colors were available also. (Really all I need to know is if any layers/groups are tagged with a certain color, i.e. RED or the hex for that.) Of course there's the additional layer state (visible/not) as well... but don't want to push my luck!

3) FYI: I don't know if this was covered elsewhere, but it appears -LayerNames has a length limitation of 31 characters, making -LayerUnicodeNames much more usable/reliable, aside from the special character ability.

Phil Harvey

Hi Chris,

1. Likely, but I don't have samples of those.

2. I don't have samples of the colors either.  The visibility would be given by LayerGroupsEnabledID (I should maybe change this name to LayerGroupsEnabled because it doesn't appear to be an ID), but this tag is marked as Unknown so you need the -u option to see it.

3. I seem to remember this, yes.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Chris S

Hey Phil, attached is an updated layer example in TIF, PSB and PSD formats tagged with colors, visibility, etc. added for reference. Thank you!
Multi-Layer Examples.zip

Chris S

By the way, I don't think LayerGroupsEnabledID is for visibility... at least running it on the Example files I just sent, I get a 1 for all, even though some of the layers and groups were saved with the visibility turned off.

Phil Harvey

You're right.  I just created a test file myself.  I found were the visibility is stored and I'll decode that too.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Phil Harvey

I got the colors too.  I'll decode this as a LayerColors tag in the next release.  All this works for the PSD, PSB and TIF samples you provided.

- Phil

I own Photoshop myself, but these layer colors and layer groups are something I've never used.
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).


Phil Harvey

Version 12.57 is now available with this update.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Chris S

Great! I'll play around with it next week. Thank you!

Chris S

Hey Phil, thank you for this. I tested it out and am able to get properly structured layers from this now. 😊

A few caveats if anyone stumbles across this post and wants to use the data elsewhere...

</Layer group>, shows up as a layer in the LayerNames and LayerUnicodeNames, and therefore has data that corresponds to it in all the other layer related lists. I'm sure this was to help understand the groupings. However, the LayerCount is reported larger than it actually is since these values are included in that count (number of layers and groups + </Layer group> entries = LayerCount ).

Since I'm reporting this through Filemaker, I'm cleaning it up a bit so it only reports the actual layers/groups and the related layer fields, in the sequence as shown in the Layer Panel. I've also added a LayerIndent field so I can still identify the folder structure before getting rid of the dividers from the various fields. This is how I did it in case anyone else comes across this post and would like to do something similar:

1. Changed all the layer related list fields to return delimited lists and dropped into a table

2. Reversed the sequence of all fields/rows (to be top-bottom as displayed in the application)

3. Created a "LayerIndent" field starting at 0 at the top and cycled through the rows, filling the "LayerIndent" field with:
    +1 when it hits a LayerSection containing "Folder"
    -1 when it reaches a Divider
    No change when it reaches a Layer.

4. Next I deleted all rows/records in the various layer lists that have a LayerSection named Divider

5. Finally I updated the LayerCount with the actual layers/groups (less Dividers) that are left

Next I need to work on the visibility in my code... though a layer is on, if it's within a group that is off, its visibility would be off/invisible. And then there's layer/group masks that is a whole different ballgame and more than I want to get into.

Ultimately, the layer structure and layer colors were what I really needed, and this gets me everything I need for that!

Thanks again.

Chris S

@Phil, not sure if this is a bug/oversight with -LayerSections, or if it was designed this way intentionally, but I noticed that if I have a multi-layered file (PSD, PSB, TIFF) that only contains layers (no folders/groups), -LayerSections doesn't return anything.

Should -LayerSections report "Layer" for all the layers in this case?

I can easily catch this in my code and assign it as a layer if it doesn't return anything, but since all the other layer-related tags are reporting something, perhaps this should as well?

FYI: I also tested a file with folders only (no layers). Not that that would ever happen/be practical, but that does correctly report those as Folders under -LayerSections.