Page 1 of 1

Multipage TIFF manipulation

Posted: 2011-05-31T04:24:42-07:00
by Oliver_CH
Hi Everybody

I'm trying to use the MSL method to automate some image manipulation. The reason for choosing MSL is the ability to script and easy customization. The example mentioned below is only the start, I will extend it further and need some characteristics of the tiff file read so I can produce the correct result.

My problem is the manipulation of multipage tiff files. In the verbose output I can see that both pages are read, but only one is written to the result file. Here is an example script, reading the file, removing the header and writing it back to disk:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<image>
	<read filename="Fax.tif" />
	<get width="base-width" height="base-height" />
	<chop geometry="0x50" />
	<get width="width" height="height" />
	<print output="Image sized from %[base-width]x%[base-height] to %[width]x%[height].\n" />	
	<write filename="Fax-out.tif" />
</image>
If called with verbose output enabled and an example file with two pages, I get the following:

Code: Select all

Fax.tif[0] TIFF 1728x2394 1728x2394+0+0 1-bit Bilevel DirectClass 110KB 0.047u 0:00.046
Fax.tif[1] TIFF 1728x2394 1728x2394+0+0 1-bit Bilevel DirectClass 110KB 0.031u 0:00.031
Image sized from 1728x2394 to 1728x2344.
Fax.tif=>Fax-out.tif TIFF 1728x2394=>1728x2344 1728x2344+0+0 1-bit Bilevel DirectClass 54.5KB 0.063u 0:00.062
msl:CutHeader.msl=>CutHeader.msl MSL 1x1 1x1+0+0 16-bit DirectClass 344B 0.125u 0:00.125
As you can see, it reads both pages, but only writes one page back to the output file.

Just for information, the final goal is to remove the existing header on all pages, put a new one at the top of every page and then write the file back to disk. The removal works if called from the command line, processing each page and writing it back as well, but not from the script.

Code: Select all

convert Fax.tif -chop  0x50 Fax-chop.tif
Any Ideas? Is this possible with MSL or is this feature missing?

Best regards
Oliver

Re: Multipage TIFF manipulation

Posted: 2011-05-31T07:15:05-07:00
by Oliver_CH
After some more tinkering, I've come up with a batch file doing what I like to do, but it has some serious drawbacks. For one it requires multiple intermediate files to be written to get to the result and for production use, some of the commands require information values out of the source file as arguments, which is kind of complicated with the batch way of doing it.

First, what I have as batch:

Code: Select all

:: Remove the top line of the pages
convert Fax.tif -fill white -draw "rectangle 0,0 1728,50" Fax-NoHeader.tif
:: create the new header
convert -size 1728x50 -depth 1 -endian LSB -alpha Off -units PixelsPerInch -density 204x196 -compress Group4 -define quantum:polarity=min-is-white -gravity center -pointsize 8 label:@Fax-Header.txt Fax-Header.tif
:: Put that new header at the top of the page
convert Fax-NoHeader.tif -draw "image SrcOver 0,0 0,0 Fax-Header.tif" Fax-Out.tif
Fax-Header.txt is a one line text file containing the text for the new header line.

As you can see, many of the arguments of the second invocation should depend on what is in the source file.

The good news with the batch method is, it works for all pages in the TIFF file.


I've tried to incorporate that into the msl but failed to create the text line into the output file, I only managed to code the first of these commands as msl, and still only working on the first page and not writing the following pages to the output file.

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<image>
	<read filename="Fax.tif" />
	<draw primitive="rectangle 0,0 1728,50" fill="white" />
	<get width="width" height="height" />
	<write filename="Fax-out.tif" />
</image>
Any pointers here?

Best regards
Oliver