Take the 2-minute tour ×

We have a large number of multipage TIF files (mainly document scans) contained in our document management system. Through various historical issues and end user misunderstandings a large number of these are considerably larger than they need to be (for example they will be scanned at a higher resolution than required, or stored without compression).

What I have been looking at doing is working through some of these documents and doing some optimisation in order to claim back some valuable storage space (I have already recovered 25GB just taking out the very low hanging fruit).

So far I have been using a combination of ImageMagick and Irfanview but I would really like to automate this process a lot more as it is pretty labour intensive at the moment. I have had a crack at creating a few scripts but unfortunately nature of the TIFs in question is proving problematic.

In particular, the majority of them contain mixed page formats; bilevel/1 bit pages for basic letter pages and full colour RGB pages for images / maps / plans. Most documents will have a mixture of these types and not always in any particular order (indeed they may go back and forth between these two formats).

Ideally I want to use group 4 fax compression on the bilevel pages and JPEG compression on the colour pages (so the -compress group4 / -compress jpeg flags in ImageMagick) but there does not appear to be any way (that I can tell - I have limited experience with IM) to set the compression on a per page format basis. Does anyone know if this is possible? Or can anyone recommend a scriptable tool that does have this capability?

Irfanview can do per page compression but it must be manually set page by page through the GUI, which is clearly not ideal.

Any tips would be greatly appreciated!

share|improve this question
Can you post a link to a sample of such a multipage TIFF with mixed page formats? I might be able to work this out with a sample file... –  Kurt Pfeifle Aug 9 '12 at 16:06
add comment

1 Answer

up vote 3 down vote accepted

Since I don't have a sample TIFF file around showing the characteristics you describe (mixed formats, different compression schemes and color spaces for different pages...), here's a first shot.

To automate the processing of multipage TIFFs you need to know that you can access each picture individually by attaching its zero-based index number [n] to the file name.

Also, you should look up the list of ImageMagick escpape shortcuts, so you can construct an identify -format <%escapestrings> command that automatically extracts the interesting bits from the file, which you'll then use to base your further processing on.

So start your project with identifying the various characteristics between the different TIFF pages by running such an identify with a customized -format string, for example:

for i in $(seq 1 $(identify -format %n multipage.tiff)); do 
  identify -format \
    "scene-number:%s \
     image-width-in-pixels:%w \
     image-height-in-pixels:%h \
     x-resolution:%x \
     y-resolution:%y \
     image-depth:%z \
     imageclass+colorspace:%r \
     image-compression-type:%C \
     image-compression-quality:%Q \
     page-width:%W \
     page-height:%H" \

(For educational reasons deliberately made more verbose than it need be...)

Based on that, you should be able to come up with a shell script that does what you need.

share|improve this answer
add comment

Your Answer


