Page 1 of 1

Check whether a tif-file is already zip-compressed

Posted: 2018-07-09T13:23:47-07:00
by DanielDD
Hallo,

I want to write a tcsh-script (for cygwin) which explores a directory-tree
and compresses each tif in the tree using zip compression. I can write
such a script but there is one problem:

For efficency, the script should skip zip-compressed files, i.e., I need
a method to check whether some tif-file is already zip-compressed.

Daniel

Re: Check whether a tif-file is already zip-compressed

Posted: 2018-07-09T14:24:20-07:00
by DanielDD
I made some research. I think it is possible using "identify -verbose filename | grep something" ,
but I am to tired, now.

Re: Check whether a tif-file is already zip-compressed

Posted: 2018-07-09T14:30:16-07:00
by fmw42
You can use the string format

%[compression] image compression type (as of IM 6.9.6-6)

See http://www.imagemagick.org/script/escape.php

In bash:

compression=$(convert image -format "%[compression]" info:)

Then do an if condition test for "$compression" = "zip"

Re: Check whether a tif-file is already zip-compressed

Posted: 2018-07-11T02:28:51-07:00
by 246246
fmw42 wrote: 2018-07-09T14:30:16-07:00 In bash:
compression=$(convert image -format "%[compression]" info:)
Then do an if condition test for "$compression" = "zip"
Small note: %[compression] returns "Zip", not "zip".

Also I found if this command applied to multi-page tiff, it returns the compress method of the first page for all pages!
(See also viewtopic.php?f=1&t=32672)

Code: Select all

c:\tmp> magick C:\tmp\logo_mix.tif -format "%[compression]\n" info:
Group4
Group4
Group4
Group4
Group4

c:\tmp> magick C:\tmp\logo_mix.tif[4] -format "%[compression]\n" info:
Zip

c:\tmp> magick C:\tmp\logo_mix.tif[0] -format "%[compression]\n" info:
Group4
So you need to count the page number first, then do check them one by one.



Edit:
It sounds like a bug, but for now better to use identify:

Code: Select all

c:\tmp> magick identify -format "%[compression]\n" C:\tmp\logo_mix.tif
Group4
LZW
LZW
LZW
Zip

Re: Check whether a tif-file is already zip-compressed

Posted: 2018-07-11T19:34:44-07:00
by fmw42
I cannot even get identify to work properly using IM 6.9.10.5 or IM 7.0.8.5 using Mac OSX Sierra.

Code: Select all

convert lena.png -compress Group4 lena1.tif
convert lena.png -compress LZW lena2.tif
convert lena.png -compress ZIP lena3.tif
convert lena1.tif lena2.tif lena3.tif -adjoin lena.tif

identify -format "%[compression]\n" lena.tif
Group4
Group4
Group4


convert lena.tif -format "%[compression]\n" info:
Group4
Group4
Group4


magick identify -format "%[compression]\n" lena.tif
Group4
Group4
Group4


magick lena.tif -format "%[compression]\n" info:
Group4
Group4
Group4

Even identify -verbose shows the same Group4 compression for all pages.

Am I not creating my test image correctly? When I view lena.tif, I see 3 pages, but they are all the same as the lena1.tif

Re: Check whether a tif-file is already zip-compressed

Posted: 2018-07-11T21:46:28-07:00
by 246246
I’m now from mobile so I cannot check it now, but it seems to be the same bug topic with viewtopic.php?f=1&t=32672, when creating multi-page tiff.

Re: Check whether a tif-file is already zip-compressed

Posted: 2018-07-11T23:25:59-07:00
by fmw42
Similar but not exactly the same. However, in either case, Imagemagick should force all settings from the first image in the list. There should be a way to prevent that, possibly with a new -define if needed (for -adjoin?). It is too late tonight for me, but one should check if the same behavior occurs for MIFF.

Part of the issue is that I am creating the multi-page tiff in Imagemagick and it looks like it puts the compression to all pages from that of the first image in the command line. However, you may have created the TIFF image in some other tool such as Photoshop. In that case, you found a bug between using convert and identify. Both should report the same different compressions if they are in the file as per identify -verbose.