How to identify layers and transparency info in PSD file ??

Started by johncarter, April 16, 2015, 09:40:53 AM

Previous topic - Next topic

johncarter

Hi,

I have a image, which contains layers (may be some are hidden by transparent layer).  While converting images to other format using ImageMagick, files having transparency losing layers.

ImageMagick guys suggested that all the layers are masked by transparent layer and when IM ignoring transparent layer, there may be a chance of losing all other layers also?

Now, is there anyway to identify any layers present in a image file and to identify if image contains transparent layers?

Or is there anyway to identify image has transparency, so that we can redirect those files to other solution for conversion?

I tried with "exiftool -a -u -g1 <imagename>" and attached below is the output for reference:


---- ExifTool ----
ExifTool Version Number         : 9.28
---- System ----
File Name                       : TestFile.psd
Directory                       : .
File Size                       : 772 MB
File Modification Date/Time     : 2014:01:16 19:20:51-06:00
File Access Date/Time           : 2015:04:16 04:48:57-05:00
File Inode Change Date/Time     : 2015:04:16 04:46:42-05:00
File Permissions                : rw-r--r--
---- File ----
File Type                       : PSD
MIME Type                       : application/vnd.adobe.photoshop
Current IPTC Digest             : f31b50bdd170d37ed37b179fd97ecc7f
Exif Byte Order                 : Little-endian (Intel, II)
---- Photoshop ----
Num Channels                    : 13
Image Height                    : 7392
Image Width                     : 9053
Bit Depth                       : 8
Color Mode                      : CMYK
IPTC Digest                     : f31b50bdd170d37ed37b179fd97ecc7f
Photoshop 0x043a                : ...printOutput.PstSbool.Inteenum[...]
Photoshop 0x043b                : ...printOutputOptions.CptnboolCl[...]
X Resolution                    : 300
Displayed Units X               : inches
Y Resolution                    : 300
Displayed Units Y               : inches
Print Scale                     : ?<80>
Alpha Channels Names            : Transparency, OL_M, White_M, Brown_M, Maroon_M, Red_M, Dark Red_M, White Text_M, Black_M
Unicode Alpha Names             : .Transparency.OL_M.White_M.Brown_M.Maroon_M.Red_M.Dark Red_M.White Text_M.Black_M
Display Info                    : <FF><FF>d..!<D7><E1><9D>.62.!<D7><E1><9D>.62.!<D7><E1><9D>.62.!<D7><E1><9D>.62.!<D7><E1><9D>.62.!<D7><E1><9D>.62.!<D7><E1><9D>.62.!<D7><E1><9D>.62
Photoshop 0x0435                : .<FF><FF>d...<FB><F9>..2..<FB><F9>..2..<FB><F9>..2[...]
Alpha Identifiers               : #$%&'()*
Background Color                : <FF><FF><FF><FF><FF><FF>
Global Angle                    : 33
Global Altitude                 : 30
Print Flags                     : .
Print Flags Info                : ..
Color Halftoning Info           : /ff.lff../ff.<A1><99><9A>..2.Z..5.-..
Color Transfer Funcs            : <FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF>.<E8><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF>.<E8><FF><FF><FF><FF>
<FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF>.<E8><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF><FF>.<E8>
Layer State Info                : .
Layers Group Info               :
Photoshop 0x0430                : ...........................
Photoshop 0x042d                : .<95>
Grid Guides Info                : ..@.@
Color Samplers Resource         : ...<AC><E5>¨..<A6>i.Q<B1><FF><FF>.<C9>..<C3>0<FF><FF>
Photoshop 0x0431                : ...E<AB>9CD§<B2>...E<A9><9A>FE<94>l&<FF><FF>..E<B2>DE<F0><CC><FF><FF>.
URL List                        :
Slices                          : ..<E0>#]..#].<E0>...null..boundsObjc.Rct1.Top longLeftlongBtomlong.<E0>Rghtlong#].slicesVlLs.Objc..slice..sliceIDlong.groupIDlong.originenum.ESliceOrigin.autoGeneratedTypeenum.ESliceTypeImg .boundsObjc.Rct1.Top longLeftlongBtomlong.<E0>Rghtlong#].urlTEXT.nullTEXT.MsgeTEXT..altTagTEXT..cellTextIsHTMLbool..cellTextTEXT..horzAlignenum.ESliceHorzAlign.default.vertAlignenum.ESliceVertAlign.default.bgColorTypeenum.ESliceBGColorTypeNone.topOutsetlong.leftOutsetlong.bottomOutsetlong.rightOutsetlong
Pixel Aspect Ratio              : .?<F0>
ICC Untagged                    : .
IDs Base Value                  : <C8>
Photoshop Thumbnail             : (Binary data 5047 bytes, use -b option to extract)
Version Info                    : ...Adobe Photoshop.Adobe Photoshop CS5.
Photoshop 0x07d0                : ..[...]
Photoshop 0x0fa0                : maniIRFR.8BIMAnDs<E0>..null.AFStl[...]
Photoshop 0x0fa1                : mfri....
---- IPTC ----
Envelope Record Version         : 4
Coded Character Set             : UTF8
Coded Character Set             : UTF8
Coded Character Set             : UTF8
Coded Character Set             : UTF8
Coded Character Set             : UTF8
Coded Character Set             : UTF8
Coded Character Set             : UTF8
Coded Character Set             : UTF8
Coded Character Set             : UTF8
Application Record Version      : 4
Date Created                    : 2013:11:19
Time Created                    : 00:00:00+00:00
---- XMP-x ----
XMP Toolkit                     : Adobe XMP Core 5.0-c060 61.134777, 2010/02/12-17:32:00
---- XMP-photoshop ----
Date Created                    : 2013:11:19
Color Mode                      : CMYK
Document Ancestors              : uuid:C4B3C0F2B152E311990B936F523C74BC, uuid:C96C5C10B252E311990B936F523C74BC, uuid:CC6C5C10B252E311990B936F523C74BC
---- XMP-aux ----
Serial Number                   : EE021045
Firmware                        : P40+-H, Firmware: Main=5.2.2, Boot=2.3, FPGA=1.2.4, CPLD=3.2.6, PAVR=1.0.3, UIFC=1.0.1, TGEN=1.0
---- XMP-xmp ----
Creator Tool                    : Adobe Photoshop CC (Macintosh)
Create Date                     : 2013:11:19 11:18:06
Modify Date                     : 2014:01:16 17:19:29-08:00
Metadata Date                   : 2014:01:16 17:19:29-08:00
---- XMP-dc ----
Format                          : application/vnd.adobe.photoshop
---- XMP-xmpMM ----
Instance ID                     : xmp.iid:5B40483B38206811B40BCE07C73A1980
Document ID                     : uuid:492D5F28B252E311990B936F523C74BC
Original Document ID            : uuid:492D5F28B252E311990B936F523C74BC
History Action                  : saved, converted, derived, saved, saved, saved
History Instance ID             : xmp.iid:9E8A2F1520181168B9E7D993609161A7, xmp.iid:9E8A2F1620181168B9E7D993609161A7, xmp.iid:faacbc50-d116-4643-aa60-e8be2e881076, xmp.iid:5B40483B38206811B40BCE07C73A1980
History When                    : 2013:12:04 10:30:35-08:00, 2013:12:04 10:30:35-08:00, 2014:01:07 10:50:21-08:00, 2014:01:16 17:19:29-08:00
History Software Agent          : Adobe Photoshop CS4 Macintosh, Adobe Photoshop CS4 Macintosh, Adobe Photoshop CC (Macintosh), Adobe Photoshop CS5 Macintosh
History Changed                 : /, /, /, /
History Parameters              : from image/tiff to application/vnd.adobe.photoshop, converted from image/tiff to application/vnd.adobe.photoshop
Derived From Instance ID        : xmp.iid:9E8A2F1520181168B9E7D993609161A7
Derived From Document ID        : uuid:492D5F28B252E311990B936F523C74BC
Derived From Original Document ID: uuid:492D5F28B252E311990B936F523C74BC
---- IFD0 ----
Image Width                     : 3491
Image Height                    : 2530
Bits Per Sample                 : 8 8 8
Compression                     : Uncompressed
Photometric Interpretation      : RGB
Make                            : Phase One
Camera Model Name               : P40+
Orientation                     : Horizontal (normal)
Samples Per Pixel               : 3
X Resolution                    : 300
Y Resolution                    : 300
Planar Configuration            : Chunky
Resolution Unit                 : inches
Software                        : Adobe Photoshop CS5 Macintosh
Modify Date                     : 2014:01:16 17:19:29
---- ExifIFD ----
X Resolution                    : 300
Y Resolution                    : 300
Resolution Unit                 : inches
Modify Date                     : 2013:11:19 11:18:06
Exposure Time                   : 1/250
F Number                        : 18.0
ISO                             : 50
Exif Version                    : 0220
Date/Time Original              : 2013:11:19 11:18:06
Create Date                     : 2013:11:19 11:18:06
Shutter Speed Value             : 1/250
Aperture Value                  : 18.0
Light Source                    : Other
Focal Length                    : 100.0 mm
Color Space                     : Uncalibrated
Exif Image Width                : 9053
Exif Image Height               : 7392
File Source                     : Digital Camera
Scene Type                      : Directly photographed
---- IFD1 ----
Compression                     : JPEG (old-style)
X Resolution                    : 72
Y Resolution                    : 72
Resolution Unit                 : inches
Thumbnail Offset                : 742
Thumbnail Length                : 0
---- Composite ----
Aperture                        : 18.0
Date/Time Created               : 2013:11:19 00:00:00+00:00
Image Size                      : 9053x7392
Shutter Speed                   : 1/250
Focal Length                    : 100.0 mm
Light Value                     : 17.3





Thanks in advance??

Phil Harvey

First, I recommend updating to a more recent version of ExifTool (9.31 or later).  Then try this command:

exiftool -u "-layer*" FILE

This will tell you how many layers, but won't tell you about their transparencies.

See http://www.adobe.com/devnet-apps/photoshop/fileformatashtml/ for the photoshop file format spec.

- 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 ($).

Stephen Marsh

#2
Ah, a recent pet topic that I was looking at via the Mac OS or Adobe Bridge. Digging a little deeper, is the following correct?


Adjustment Layer = Layer Selection IDs: 4

Raster Layer = Layer Selection IDs: 3

Text Layer = Layer Selection IDs: 5

Vector Shape Layer = Layer Selection IDs: 5

__________

A "flat" background layer with four layers (adjustment, raster, text, shape) = Layer Selection IDs: 6

Layers Group Info: 0 0 0 0 0
Layer Groups Enabled ID: 1 1 1 1 1

So the above two lines appear to indicate that there are a total of 5 layers, which makes sense.

__________


If so, curious minds enquire about Layer Selection IDs: 1 and 2?!


Stephen Marsh

A user of another forum offered the following Mac OS shell script solution for layered TIFF files, I am guessing that it is simple enough to modify for PSD:

#!/bin/bash

TIFFEXTENSIONONLY=0

cd "$(dirname "${BASH_SOURCE[0]}")"
SAVEIFS=$IFS
IFS=$(/bin/echo -n $'\n\b')
if [[ TIFFEXTENSIONONLY -eq 0 ]]; then
for N in $(find . -maxdepth 1 -type f ! -name '._*'); do
if [[ $(head -c 2 "$N") == II ]] || [[ $(head -c 2 "$N") == MM ]]; then
tiffutil -dump "$N" | grep '^37724 (0x935c)' > /dev/null
if [[ $? -eq 0 ]]; then
mkdir -p 'MULTIPLE LAYERS'
mv -n "$N" 'MULTIPLE LAYERS'
fi
fi
done
else
for N in $(find -E . -maxdepth 1 -iregex '.*tif(f){0,1}' ! -name '._*'); do
if [[ $(head -c 2 "$N") == II ]] || [[ $(head -c 2 "$N") == MM ]]; then
tiffutil -dump "$N" | grep '^37724 (0x935c)' > /dev/null
if [[ $? -eq 0 ]]; then
mkdir -p 'MULTIPLE LAYERS'
mv -n "$N" 'MULTIPLE LAYERS'
fi
fi
done
fi
IFS=$SAVEIFS
echo TIFF layer checking finished $(date)

Stephen Marsh

A user at the Adobe Bridge Scripting forum posted this JavaScript/ExtendScript solution for Bridge:

#target bridge   
   if( BridgeTalk.appName == "bridge" ) {   
tifLayers= MenuElement.create("command", "Tifs With Layers", "at the end of Tools"); 

tifLayers.onSelect = function () {   
var fileList = Folder(app.document.presentationPath).getFiles("*.tif"); 
withLayers = new Array(); 
for(var x in fileList){ 
var file = fileList[x]; 
file.open("r"); 
file.encoding = 'BINARY'; 
var dat = file.read(); 
file.close(); 
var result; 
var pos = []; 
var Text= []; 
var rex = /Adobe Photoshop Document Data Block/g; 
while ((result = rex.exec(dat)) != null) { 
pos.push(result.index+(result[0].length)); 

if(pos.length>0) withLayers.push(new Thumbnail(fileList[x])); 
dat=null; 

if(withLayers.length >0){ 
var foundFiles = app.createCollection("Tifs With Layers"); 
app.addCollectionMember(foundFiles,withLayers); 
    } 
};


It uses Bridge's "Collections" feature.

Phil Harvey

The first script is equivalent to this ExifTool command:

exiftool -if '$ImageSourceData' -directory="MULTIPLE LAYERS" DIR

I don't know about the layer numbers.  When I get a chance I'll look into this.

- 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 ($).

Stephen Marsh

#6
Quote from: Phil Harvey on February 19, 2016, 07:19:22 AM
The first script is equivalent to this ExifTool command:

exiftool -if '$ImageSourceData' -directory="MULTIPLE LAYERS" DIR

Thanks Phil, what if one wished to create the new directory MULTIPLE LAYERS in the same source directory as the original files (presuming no sub-directories)?

Is there a relative wildcard that stands for the source directory, or would one have to hard code in the absolute path before MULTIPLE LAYERS?

On a related note, as the above is only for TIFF, I tried to use the following (with different variations) to sort both TIFF and PSD, however the condition fails:

exiftool -if '-layer*' -directory="MULTIPLE LAYERS" DIR


P.S. Rather than moving original files, can ExifTool create an alias on the Mac or a shortcut in Windows to the originals?


QuoteI don't know about the layer numbers.  When I get a chance I'll look into this.

- Phil

Thank you!

Phil Harvey

Quote from: Stephen Marsh on February 19, 2016, 07:04:18 PM
Quote from: Phil Harvey on February 19, 2016, 07:19:22 AM
exiftool -if '$ImageSourceData' -directory="MULTIPLE LAYERS" DIR

Thanks Phil, what if one wished to create the new directory MULTIPLE LAYERS in the same source directory as the original files (presuming no sub-directories)?

Either -directory="DIR/MULTIPLE LAYERS" or -directory=%dMULTIPLE LAYERS"

QuoteIs there a relative wildcard that stands for the source directory

Yes:  %d

QuoteOn a related note, as the above is only for TIFF, I tried to use the following (with different variations) to sort both TIFF and PSD, however the condition fails:

exiftool -if '-layer*' -directory="MULTIPLE LAYERS" DIR

I don't have time to look into how to detect multiple layers in a PSD file right now, but try adding the -u option and extract all metadata to see what the file contains.

QuoteP.S. Rather than moving original files, can ExifTool create an alias on the Mac or a shortcut in Windows to the originals?

If a hard link will do what you want, you can create them by writing the HardLink tag: -hardlink="%dMULTIPLE LAYERS/%f.%e"

- 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

Quote from: Phil Harvey on February 19, 2016, 07:19:22 AM
I don't know about the layer numbers.  When I get a chance I'll look into this.

These numbers are just the ID number for the selected layer(s).  They have no significance (other than possibly being ordered sequentially as the layers were added).

- 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 ($).

mikmach

Couldn't find info about layer tags in other places and this thread comes first in Google when asking about layers and exiftool so:

When TIF file doesn't have any layers (has only special Background layer)  this returns nothing:

exiftool -u "-layer*" file.tif

Info about layers appears when we change regular Background into normal layer:

Layers Group Info               : 0
Layer Groups Enabled ID         : 1
Layer Selection IDs             : 5


If you add normal layers it will add digits in 1st and 2nd row:

Layers Group Info               : 0 0
Layer Groups Enabled ID         : 1 1
Layer Selection IDs             : 6


Layer Selection IDs is ticking up but don't take it seriously, there are additional rules about tag - cannot now test all of them. But one of them could be useful: when file has special Background layer it always stays equal to 1, regardless of selected layer (at least looks that way in my limited tests).

Fun starts when you add one another layer and group two of them:

Layers Group Info               : 0 0 0 0 0
Layer Groups Enabled ID         : 1 1 1 1 1
Layer Selection IDs             : 8


There are three layers and two of them are grouped. Group 'header' and whole group have their own entries in first two rows. I don't see a way to distinguish what is what.

BTW better way to get layer info is

exiftool -u "-*layer*" file.tif

You get info about additional tag: TargetLayerID.

Answering another question. To get info about transparent layers/channels use AlphaChannelsNames. There is list of names separated with commas.

HTH

Phil Harvey

...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 ($).

mbo

hello everybody,

is there a way to get the layer name? The given information by using

exiftool -u "-*layer*" layers.tif


Target Layer ID                 : 2
Layers Group Info               : 0 0 0
Layer Groups Enabled ID         : 1 1 1
Layer Selection IDs             :

are not enough for me. I want to separate files which have a special named layer. But i can not find a matching key in the metadata.

An String array like below would be helpful.
Layer Names : layer 1, layer 2

thank you in advance!

Phil Harvey

Thanks for this sample.  The layer names are hidden in the ImageSourceData block of this file.  It will be some work to decode this, but I'll see what I can do.

- 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've looked into this and it is possible, but will require significant changes to the code which will have to wait until after ExifTool 11.00 is released in a couple of weeks.

- 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've been working on this, and have a test version extracting this information.

I'll test this as thoroughly as possible, and if all goes well this update may appear in version 10.99 after all.

- 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 ($).

mbo

Hello Phil,

many Thanks! I am very happy that it is possible to get this information soon by using ExifTool.

Marvin

mbo

Hello Phil,

i have testes your new ExifTool Version 10.99. The result is great.

I want to document that a little bit for all forum users.


exiftool -LayerNames -LayerUnicodeNames layers.tif


Layer Names                     : Hintergrund, layer 1, layer 2
Layer Unicode Names             : Hintergrund, layer 1, layer 2

The output "Layer Unicode Names" is very useful if special characters are set in layer name. Like german "ä", "ü", or "ö".


exiftool -LayerCount layers.tif


Layer Count                     : 3

With that info it is very simple to check the count of given layers in the file.


exiftool -LayerOpacities -LayerBlendModes layers_opacity.tif


Layer Opacities                 : 100%, 50%, 100%
Layer Blend Modes               : Normal, Screen, Multiply

In Photoshop you can set the layer opacity and a blend mode. See also https://photoblogstop.com/photoshop/photoshop-blend-modes-explained


exiftool -LayerRectangles layers_rectangles.tif


Layer Rectangles                : 0 0 256 256, 0 0 256 256, 0 64 128 192

The last layer "layer 3" is smaller. You can read the coordinates like:
Top left: x=64, y=0
Bottom right: x=192, y=128

All infos you will get using this command:

exiftool -u -"*layer*" layers.tif


Target Layer ID                 : 2
Layers Group Info               : 0 0 0
Layer Groups Enabled ID         : 1 1 1
Layer Selection IDs             : 6
Layer Count                     : 3
Layer Rectangles                : 0 0 256 256, 0 0 256 256, 0 64 128 192
Layer Blend Modes               : Normal, Screen, Multiply
Layer Opacities                 : 100%, 50%, 100%
Layer Names                     : Hintergrund, layer 1, layer 2
Layer Unicode Names             : Hintergrund, layer 1, layer 2
Layer IDs                       : 1, 4, 6
Layer Modify Dates              : 2018:06:05 15:38:27+02:00, 2018:06:05 15:38:27+02:00, 2018:06:05 15:38:27+02:00


So Phil, thanks a lot!

regards, Marvin

Phil Harvey

Hi Marvin,

Great.  Thanks for documenting this.

- 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 ($).