Saving multipage TIF
Saving multipage TIF
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!
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Saving multipage TIF
Are you writing the same information to each page or different information on each page.
If the same information, then see gif animations (http://www.imagemagick.org/Usage/anim_mods/#composite). 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.
If the same information, then see gif animations (http://www.imagemagick.org/Usage/anim_mods/#composite). 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
I really only have to write the information on the top page, all the other pages can stay as they are.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Saving multipage TIF
clone the first page, then write to it, then replace the old first page with the new one.
Re: Saving multipage TIF
Are you writing the MagickImageCollection or the MagickImage to disk?
Re: Saving multipage TIF
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 .
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 .
-
- Posts: 4
- Joined: 2017-05-12T05:41:51-07:00
- Authentication code: 1151
Re: Saving multipage TIF
Hi,
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!
Mihai.
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!
Mihai.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Saving multipage TIF
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?
Tell us exactly what command you used (or what program you wrote).
What result did you get? What result did you want?
snibgo's IM pages: im.snibgo.com
-
- Posts: 4
- Joined: 2017-05-12T05:41:51-07:00
- Authentication code: 1151
Re: Saving multipage TIF
Hi,
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="7.0.5.502"
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,
Mihai.
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="7.0.5.502"
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,
Mihai.
-
- Posts: 4
- Joined: 2017-05-12T05:41:51-07:00
- Authentication code: 1151
Re: Saving multipage TIF
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:
https://drive.google.com/file/d/0B0zlZw ... sp=sharing
The source code is here:
You should be able to download the zip with the solution here:
https://drive.google.com/file/d/0B0zlZw ... 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");
images.Read("../../res/sample.tif");
// 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));
newImages.Add(img);
index++;
}
// write the new collection to disc
Console.WriteLine("writing the new file...");
newImages.Write("../../res/sample_new.tif");
}
}
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Saving multipage TIF
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.
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.
snibgo's IM pages: im.snibgo.com
Re: Saving multipage TIF
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: https://github.com/ImageMagick/ImageMagick/issues/425.
-
- Posts: 4
- Joined: 2017-05-12T05:41:51-07:00
- Authentication code: 1151
Re: Saving multipage TIF
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!
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!