Check whether a tif-file is already zip-compressed

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
DanielDD
Posts: 17
Joined: 2013-10-28T01:57:10-07:00
Authentication code: 6789

Check whether a tif-file is already zip-compressed

Post by DanielDD » 2018-07-09T13:23:47-07:00

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

DanielDD
Posts: 17
Joined: 2013-10-28T01:57:10-07:00
Authentication code: 6789

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

Post by DanielDD » 2018-07-09T14:24:20-07:00

I made some research. I think it is possible using "identify -verbose filename | grep something" ,
but I am to tired, now.

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

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

Post by fmw42 » 2018-07-09T14:30:16-07:00

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"

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

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

Post by 246246 » 2018-07-11T02:28:51-07:00

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

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

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

Post by fmw42 » 2018-07-11T19:34:44-07:00

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

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

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

Post by 246246 » 2018-07-11T21:46:28-07:00

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.

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

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

Post by fmw42 » 2018-07-11T23:25:59-07:00

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.

Post Reply