Page 1 of 1

Saving multipage TIF

Posted: 2015-07-08T14:00:22-07:00
by sheier
Hello all, I am trying to take in a multi-page TIF, overlay some text on the first page, and then save it again. I'm able to load the file as a MagickImageCollection and loop through the pages, but when I write it back to disk it is always only the first page of the TIF. I am using VS.NET. Does anyone have experience with this type of operation? Thanks in advance!

Re: Saving multipage TIF

Posted: 2015-07-08T14:06:31-07:00
by fmw42
Are you writing the same information to each page or different information on each page.

If the same information, then see gif animations ( I believe you can do the same with multilayer tiff files.

If separate information to each page, then you probably need to clone each page, write to it, delete the originals and then combine the modified pages into a new image.

Re: Saving multipage TIF

Posted: 2015-07-08T14:09:19-07:00
by sheier
I really only have to write the information on the top page, all the other pages can stay as they are.

Re: Saving multipage TIF

Posted: 2015-07-08T14:36:09-07:00
by fmw42
clone the first page, then write to it, then replace the old first page with the new one.

Re: Saving multipage TIF

Posted: 2015-07-08T21:50:30-07:00
by dlemstra
Are you writing the MagickImageCollection or the MagickImage to disk?

Re: Saving multipage TIF

Posted: 2015-08-03T10:58:27-07:00
by ceepea
ARGH!!!! Found the problem, do not know if this is in a FAQ but hopefully others will see this.

Wrong "convert" program was running.
The built in "convert" of Win7 which converts file systems was being run, not the IM convert.
When i specified the path to the IM convert, image creation worked fine.

(the other day i had adjusted the path to go to IM first, that adjustment got lost upon reboot of pc)

Thank you for the working scripts .

Re: Saving multipage TIF

Posted: 2017-05-12T07:23:09-07:00
by mihail_potcoava

I'm having exactly the same problem as described in this thread:
"I'm able to load the file as a MagickImageCollection and loop through the pages, but when I write it back to disk it is always only the first page of the TIF"

Unfortunately, I don't understand the solution ("Wrong "convert" program was running.")
Where I can find the "IM convert"?
How can I change the path to go to IM convert first?

Any advice is appreciated, I'm struggling for some time now and I can't seem to find a solution.

Many thanks!

Re: Saving multipage TIF

Posted: 2017-05-12T07:40:14-07:00
by snibgo
Please tell us what version of IM you use, on what platform.

Tell us exactly what command you used (or what program you wrote).

What result did you get? What result did you want?

Re: Saving multipage TIF

Posted: 2017-05-13T00:17:37-07:00
by mihail_potcoava

Many thanks for getting back to me so quickly.

I've built a small test console application with my scenario (something simple).
If you could open the solution and run it would be great. I think it's the quickest way to understand the problem.

Some details:
Platform: Windows 10, .Net Framework 4.5.2
NugetPackage: id="Magick.NET-Q16-AnyCPU" version=""

Basically, I want to load a layered tiff file, change one of the layers and then rebuild the tiff file (as layered).
Everything seems to work ok but the resulting tiff file (sample_new.tif) looks like the first layer (when opened with any windows program).

If I open the resulting tiff (sample_new.tif) again it looks ok, all the layers are there, but now sure why the tiff file is not looking as if all layers are combined.

I hope it's clear, please advise.

Many thanks for your help,

Re: Saving multipage TIF

Posted: 2017-05-13T00:26:10-07:00
by mihail_potcoava
Sorry, I thought I can attach the zip containing the .NET solution but it seems I can't.

You should be able to download the zip with the solution here: ... sp=sharing

The source code is here:

Code: Select all

	    // read the sample tif file
            using (MagickImageCollection images = new MagickImageCollection())
                Console.WriteLine("reading the tif file");

                // there should be 8 layers. (not sure why the first layer is the tif image and the seccond seems invalid)
                // iterate through layers, replace layer 4 color with a new one
                Console.WriteLine("changing layer nr 4");
                var oldColor = System.Drawing.ColorTranslator.FromHtml("#FEAF5C");
                var newColor = System.Drawing.ColorTranslator.FromHtml("#00ff00");
                images[4].Opaque(MagickColor.FromRgb(oldColor.R, oldColor.G, oldColor.B), MagickColor.FromRgb(newColor.R, newColor.G, newColor.B));

                // try to re-build the original tiff file but with one layer changed
                //just to be sure we're creating a new collection to skip the first two layers
                using (MagickImageCollection newImages = new MagickImageCollection())
                    // add layers to a new collection
                    Console.WriteLine("copying to new collection and write each layer");
                    int index = 0;
                    foreach (var img in images.Skip(2))
                        // just to be sure the layers look good we're going to save all as PNG
                        img.Write(string.Format("../../res/layer_{0}_.png", index));


                    // write the new collection to disc
                    Console.WriteLine("writing the new file...");

Re: Saving multipage TIF

Posted: 2017-05-13T01:24:15-07:00
by snibgo
Sorry, I know nothing about Magick.NET.

You zip file contains res/sample.tif, which contains eight images. I suppose this is your input file. It might be helpful if you also showed your output res/sample_new.tif.

Re: Saving multipage TIF

Posted: 2017-05-13T04:49:06-07:00
by dlemstra
Your tiff file is organized like this: [merged image] [layer 1] [layer2] etc. The layers are normally not visible in an image viewer but Magick.NET knows how to extract the Photoshop layers. So your code should do images.Skip(1) instead and make the first image the new 'merged image' of all the layers (index 1 to 7). But that won't help you yet because writing multi layer TIFF files is not supported at the moment. Your multi layer tiff file is changed into a multi page tiff file. We have created an issue on github to add this at some point in the future:

Re: Saving multipage TIF

Posted: 2017-05-13T06:08:06-07:00
by mihail_potcoava
Many thanks for your reply.

I honestly thought that pages and layers in a tiff are the same thing.

I'll dig more, install evince / tiffinfo / photoshop to understand better.

the good thing is that I know now why my resulting tiff looks like the fist layer / page.

So I can Combine / Coalesce all the layers and add the resulting layer to be the first one and this way it will look ok.

Thanks again for your help and quick answer!