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
Check whether a tif-file is already zip-compressed
Re: Check whether a tif-file is already zip-compressed
I made some research. I think it is possible using "identify -verbose filename | grep something" ,
but I am to tired, now.
but I am to tired, now.
- fmw42
- Posts: 25562
- 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
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"
%[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
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
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
- fmw42
- Posts: 25562
- 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
I cannot even get identify to work properly using IM 6.9.10.5 or IM 7.0.8.5 using Mac OSX Sierra.
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
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
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
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.
- fmw42
- Posts: 25562
- 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
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.
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.