photoshop tiff files - counting/exporting layers to jpg

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?".
Post Reply
russellbarnhart

photoshop tiff files - counting/exporting layers to jpg

Post by russellbarnhart »

hi. ive been struggling this all day, so i figured i'd ask. all the following is taking place via the command line.

here is the output of 'convert -version'
Version: ImageMagick 6.4.9-10 2009-03-09 Q16 OpenMP http://www.imagemagick.org
im using version 3.8.2 of libtif

the image im testing with is here:
http://itsalmostreal.com/gnu/imagemagick/test.tif

here is a screenshot of the file open in photoshop, showing the layers:
http://itsalmostreal.com/gnu/imagemagick/ps_grab.png

here is a screengrab of the settings used when i save the file (though i have tried every other combination and had the same results):
http://itsalmostreal.com/gnu/imagemagic ... ttings.png

here are the commands and results that im running
identify command: identify -format "%[scenes]" test.tif
result:
identify: test.tif: unknown field with tag 37724 (0x935c) encountered. `TIFFReadDirectory' @ tiff.c/TIFFWarnings/526.
identify: test.tif: unknown field with tag 40961 (0xa001) encountered. `TIFFReadCustomDirectory' @ tiff.c/TIFFWarnings/526.
identify: test.tif: unknown field with tag 37724 (0x935c) encountered. `TIFFReadDirectory' @ tiff.c/TIFFWarnings/526.
0

i understand that the 3 errors are most-likely just proprietary tag read errors, and actually have no effect on the outcome. its the 0 that bothers me. the file definitely has 3 layers, so im not sure why its telling me 0.

convert command: convert test.tif[2] layer_2.jpg
result: yields the same tag read errors, and creates a file with all 3 layers merged.

can anyone provide me with any insight? my main goal is to be able to take a multilayer tiff file, count the number of layers, and then output a thumbnail of each layer.

is this going to be possible? i feel like i must be making a silly mistake. thanks for any and all help. its greatly appreciated.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: photoshop tiff files - counting/exporting layers to jpg

Post by fmw42 »

Your original file is inaccessible for our testing. It gives a FORBIDDEN error. Check the permissions.
russellbarnhart

Re: photoshop tiff files - counting/exporting layers to jpg

Post by russellbarnhart »

sorry about that. i changed the permissions and the file is accessible now. thanks.
russellbarnhart

Re: photoshop tiff files - counting/exporting layers to jpg

Post by russellbarnhart »

anyone have any ideas regarding this?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: photoshop tiff files - counting/exporting layers to jpg

Post by magick »

You are getting the scene number instead of the number of scenes. This bug is fixed in the latest release of ImageMagick, available sometime tomorrow). Thanks for the problem report.
russellbarnhart

Re: photoshop tiff files - counting/exporting layers to jpg

Post by russellbarnhart »

ive just installed from source the latest version (6.5.0-1) and i still have the same issue.

does imagemagick recognize the layers in tif files created by photoshop?

see page 11 of http://partners.adobe.com/public/develo ... toshop.pdf
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: photoshop tiff files - counting/exporting layers to jpg

Post by fmw42 »

Testing a simple case:

create 3 frame gif
convert rose: rose: rose rose3.gif

get info in various ways:

identify rose3.gif
rose3.gif[0] GIF 70x46 70x46+0+0 8-bit PseudoClass 256c 10.6kb
rose3.gif[1] GIF 70x46 70x46+0+0 8-bit PseudoClass 256c 10.6kb
rose3.gif[2] GIF 70x46 70x46+0+0 8-bit PseudoClass 256c 10.6kb

identify -format "%[scenes]" rose3.gif
333

identify -format "%[scenes]\n" rose3.gif
3
3
3

identify -format "%[scene]\n" rose3.gif
0
1
2

So strangely, the second to last method, tells you for each frame that there are 3 frames in the image.

However, the last one, tells you the number of each frame. So you can get the last value and add one to it to compute the total frames.

I downloaded your test.tif file and it has only one frame when I open it in Mac Preview. When I try to do

identify test.tif

it chokes my system.
visitor x
Posts: 16
Joined: 2013-07-27T13:26:38-07:00
Authentication code: 6789

Re: photoshop tiff files - counting/exporting layers to jpg

Post by visitor x »

To extract all layers to jpgs, you can do something like:

Code: Select all

for i in $(identify -format "%[scene] " <filename>.tiff); do convert <filename>.tiff[$i] <extracted-filename>-$i.jpg; done 
(ImageMagick 6.8.9-9 Q16 i686 2015-01-06)

I've changed "%[scene]\n" for "%[scene] ", so this is equivalent to do

Code: Select all

for i in 0 1 2 4 5 6 7 etc; do ... done
More loops examples: http://www.cyberciti.biz/faq/bash-for-loop/

Hope it helps!
Andrrr
Post Reply