Tiff with layers boolean?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
josephaaroncampbell
Posts: 40
Joined: 2015-07-14T19:18:45-07:00
Authentication code: 1151
Location: Chicago, IL

Tiff with layers boolean?

Post by josephaaroncampbell » 2015-07-14T23:02:57-07:00

Hello!

So I have read as much as i can find about ImageMagick and tif files with layers. My goal is to simply return a yes or no as to whether or not a .tif has extra layers. (as in more than just the base layer [0])

I have tried to return the layer information with:

identify -format %p -%n image.tif

...but %p always returns 0, and %n always returns 1.

in doing so i have learned that layers are not pages or scenes and are stored in specific metadata tags that may or may not be available to read in imageMagick

So is there a known method to count the layers, list the layers, or simply return a yes or no if a .tiff file has layers?

I will look over the forum again and make sure i understood everything I have read.

Thank You for your time!

*the ultimate goal is to scan a large folder of .tif images and write the files names of each layered .tif to a text file while skipping the files with no extra layers.

using ImageMagick-6.9.1-Q16-HDRI
windows 7 64 bit

User avatar
fmw42
Posts: 25566
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Tiff with layers boolean?

Post by fmw42 » 2015-07-14T23:34:41-07:00

simple layers can be determined by your identify command with %n ( whys do you have a - before the %)

Code: Select all

convert rose: rose: rose: rose.tif
identify -format "%n\n" rose.tif
333
Since there are 3 layers, %n reports the total number 3 times as 333

or

Code: Select all

identify -format "%s" rose.tif
012
which lists the scene id numbers starting with 0, so for 3 layers it would say 012.

or same as above

Code: Select all

identify -format "%[scene]" rose.tif
012


I prefer

Code: Select all

dentify rose.tif
rose.tif[0] TIFF 70x46 70x46+0+0 8-bit sRGB 29.8KB 0.000u 0:00.000
rose.tif[1] TIFF 70x46 70x46+0+0 8-bit sRGB 29.8KB 0.000u 0:00.000
rose.tif[2] TIFF 70x46 70x46+0+0 8-bit sRGB 29.8KB 0.000u 0:00.000
This clearly shows 3 layers.

Processing of tif files with special layers have only recently been added to IM. See changelog at http://www.imagemagick.org/script/changelog.php, but I do not know if these types of layers can be identified via these commands. The IM developers would need to check that or comment.


2015-05-25 6.9.1-4 Dirk Lemstra <dirk@lem.....org>
Added support for reading a user supplied layer mask in PSD files.
Added support for reading photoshop layers in TIFF files.

Perhaps you should upload one of your tif files to dropbox.com and put the URL here, so that the IM developers can check what type of layers it has or if corrupt.

User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Tiff with layers boolean?

Post by dlemstra » 2015-07-15T00:51:02-07:00

The following will work to print the number of images in the list:

Code: Select all

C:\Images\Tif\layers>identify -format "%n" image_3layer_ps.tif
333
C:\Images\Tif\layers>identify -format "%n" lena.jpg
1
But it is possible that you have a multi page tiff instead of a tiff file with multiple frames. You can better detect it like this:

Code: Select all

C:\Images\Tif\layers>identify -format "%[profiles]" image_3layer_ps.tif
8bim,iptc,tiff:37724,xmp
This will print out the profile names and if it contains the profile 'tiff:37724' it means that ImageMagick will try to read the photoshop layers.

I would advise you to wait for the next release of ImageMagick (6.9.1-9) this includes a fix for an initialized variable that can cause unwanted changes in the colorspace.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate

246246
Posts: 190
Joined: 2015-07-06T07:38:22-07:00
Authentication code: 1151

Re: Tiff with layers boolean?

Post by 246246 » 2015-07-15T06:37:26-07:00

dlemstra wrote: But it is possible that you have a multi page tiff instead of a tiff file with multiple frames. You can better detect it like this:

Code: Select all

C:\Images\Tif\layers>identify -format "%[profiles]" image_3layer_ps.tif
8bim,iptc,tiff:37724,xmp
This will print out the profile names and if it contains the profile 'tiff:37724' it means that ImageMagick will try to read the photoshop layers.
Well, but the existence of profile 37724 does not always means tiff has user defined layer in Photoshop, for example, see this one. https://www.dropbox.com/s/z6fy25uzg2mwz ... o.tif?dl=0
Photoshop shows only 1 layer. (This file is also an example that only photoshop shows transparent background whereas other program, IM display or gimp does not.)

So, as of IM 6.9.1-8, to distinguish between multi-page and multi-layer tiff, we have to do something like

Code: Select all

#!/bin/sh
IDENTIFY="/usr/local/bin/identify"

pages=`"$IDENTIFY" -quiet -define 'tiff:ignore-layers=true' -format '%p\n' "$1" | grep -v '^$' | tail -1`
layers=`"$IDENTIFY" -quiet -format '%p\n' "$1" | grep -v '^$' | tail -1`

if [ "$pages"x == "$layers"x ]
then
  echo 0 # photoshop layer
else
  echo 1 # multi page
fi
and it's slow.

So I think at least 'identify -verbose ' should some information whether IM really read the photoshop layer or not.
Last edited by 246246 on 2015-07-15T07:26:08-07:00, edited 1 time in total.

User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Tiff with layers boolean?

Post by dlemstra » 2015-07-15T07:55:47-07:00

I could add an extra attribute to the image that will let you know if the PSD layers where read. I'll get back to this topic what it has been added.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate

User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Tiff with layers boolean?

Post by dlemstra » 2015-07-18T14:47:29-07:00

The attribute has been added an will be available in the next release (6.9.1-10) and can be used like this:

Code: Select all

D:\Images\tif\layers>identify -format "%[tiff:has-layers]" OneLayerAgainstTransparency.tif[0]
true
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate

246246
Posts: 190
Joined: 2015-07-06T07:38:22-07:00
Authentication code: 1151

Re: Tiff with layers boolean?

Post by 246246 » 2015-07-25T07:26:10-07:00

It looks OK if provided multi-layer tiff, but with 6.9.1-10

Code: Select all

>identify -format "%[tiff:has-layers]\n" Hello.tif
identify.exe: Incompatible type for "RichTIFFIPTC"; tag ignored. `TIFFFetchNormalTag' @ warning/tiff.c TIFFWarnings/856.
identify.exe: unknown image property "%[tiff:has-layers]" @ warning/property.c/InterpretImageProperties/3600.
I expected it returns false (and not produce warning "unknown image property".)

Hello.tif is in my previous post, but it seems every non-layerd tiff generate this warning.

User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Tiff with layers boolean?

Post by dlemstra » 2015-07-25T07:57:19-07:00

The property will only be set when the image contains layers and that is why you are getting this warning. You should probably add -quiet to avoid the noise and also only check the first 'frame' by adding [0].

Code: Select all

identify -quiet -format "%[tiff:has-layers]\n" Hello.tif[0]
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate

246246
Posts: 190
Joined: 2015-07-06T07:38:22-07:00
Authentication code: 1151

Re: Tiff with layers boolean?

Post by 246246 » 2015-07-25T08:58:53-07:00

I understand why. So checking multi page or multi flame is archived easier. Thank you again.

identify -quiet -format "%n %[tiff:has-layers]\n" unknown.tif | tail -1

outputs:

1

for single-page & no layer tiff;

2

for 2 page tiff;

3 true

for 3 layer tiff. (Indeed 2 layers. As [0] is automatically added.)

Omitting [0] is for avoiding multiple call of identify. It seems safe.
Last edited by 246246 on 2015-08-07T18:40:57-07:00, edited 1 time in total.

User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Tiff with layers boolean?

Post by dlemstra » 2015-07-25T09:43:09-07:00

The property will be set on the image and all its layers so that means you can get something like this:

truetruetrue

if the image has two layers and that is why I suggested you to add the [0]
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate

246246
Posts: 190
Joined: 2015-07-06T07:38:22-07:00
Authentication code: 1151

Re: Tiff with layers boolean?

Post by 246246 » 2015-07-25T16:21:05-07:00

dlemstra wrote:The property will be set on the image and all its layers so that means you can get something like this:

truetruetrue
I am aware of it. Here, I wanted to show convenient one-liner, (although tail is unix specific.)

josephaaroncampbell
Posts: 40
Joined: 2015-07-14T19:18:45-07:00
Authentication code: 1151
Location: Chicago, IL

Re: Tiff with layers boolean?

Post by josephaaroncampbell » 2015-08-03T13:11:36-07:00

Thank You ALL for your responses. I am busy working my way through all of this information. I will surely update with my progress soon.

Thank You again!

josephaaroncampbell
Posts: 40
Joined: 2015-07-14T19:18:45-07:00
Authentication code: 1151
Location: Chicago, IL

Re: Tiff with layers boolean?

Post by josephaaroncampbell » 2015-08-07T14:10:28-07:00

dlemstra wrote:The attribute has been added an will be available in the next release (6.9.1-10) and can be used like this:

Code: Select all

D:\Images\tif\layers>identify -format "%[tiff:has-layers]" OneLayerAgainstTransparency.tif[0]
true

Hello! I hope i can get your advice at this moment.

So I have been going through the documentation and other sources working on this. I cannot get this to work however. using the binary release for 6.9.1-10 (http://www.imagemagick.org/script/binar ... hp#windows) gives me the following error:

"identify.exe: unknown image property "%[tiff:has-layers]" @warning/property.c/interpretImageProperties/3600"

I know this was mentioned in the replies already and was in reference to non-layered tiff files. However, this error is occurring for both layered and non-layered tiffs on my end. I have tried layered tiffs created using imageMagick as well as Adobe Photoshop.

My first assumption was to try the subversions, going off of your quote, that more likely it was added there and not the binary release from the main download page.

Currently I am running windows7 x64 on one machine and windows 10 x64 on another
ImageMagick 6.9.1-10 Q16 x64 2015-07-25

The other options i was looking into was compiling from the source code, but I am new to that and its been a learning curve. As well as possibly reading the 8BIM data since these files where created in adobe photoshop and layer data is stored in the 37724 tags of the metadata.

I have tried to cover all the options, but I am not sure how to approach this.

Thank You

User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Tiff with layers boolean?

Post by dlemstra » 2015-08-07T14:55:02-07:00

Can you share your image on something like dropbox? The one where you think/know that it has layers?
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate

246246
Posts: 190
Joined: 2015-07-06T07:38:22-07:00
Authentication code: 1151

Re: Tiff with layers boolean?

Post by 246246 » 2015-08-07T21:47:08-07:00

I can reproduce this problem with this tiff:
https://www.dropbox.com/s/heuy7yj037azlhb/test.tif?dl=0
In Photoshop CS6 it is shown as
Image

Code: Select all

C:\>identify -format "%[tiff:has-layers]\n" V:\tmp\test.tif[0]
identify.exe: Incompatible type for "RichTIFFIPTC"; tag ignored. `TIFFFetchNormalTag' @ warning/tiff.c/TIFFWarnings/856.
identify.exe: unknown image property "%[tiff:has-layers]" @ warning/property.c/InterpretImageProperties/3600.

C:\>identify -quiet V:\tmp\test.tif
V:\tmp\test.tif TIFF 393x379 393x379+0+0 8-bit sRGB 204KB 0.031u 0:00.044
But If I saved it as psd in PhotoShop, it detects 2 layers.
https://www.dropbox.com/s/o3pdwu0qj89pl3j/test.psd?dl=0

Code: Select all

C:\>identify V:\tmp\test.psd
V:\tmp\test.psd[0] PSD 393x379 393x379+0+0 8-bit sRGB 346KB 0.016u 0:00.010
V:\tmp\test.psd[1] PSD 347x335 347x335+22+21 8-bit sRGB 346KB 0.000u 0:00.012
V:\tmp\test.psd[2] PSD 178x167 178x167+111+107 8-bit sRGB 346KB 0.000u 0:00.020

Post Reply