0

I have to convert multipple tiff to separate png files.For isntance i have a tiff file which have a 3 pages and i'd like to convert it 3 separate png's.In below code i could only convert first page of tiff file into png.

gm(__dirname+'/Tiff/Recorded.tiff').write(__dirname+'/Png/cpng.png',(err)=>{
if(!err){
    console.log('Done');
}
else {
    console.log(err);
}

});

How could i convert for example a second page of this tiff file?

And second question regarding adding a tiff file into another tiff.For example i have tiff file with one page and have second tiff file with three pages? I investigate i have found the append method but it was not working.The code below!

gm(__dirname+'/Tiff/Recorded.tiff')
.append(__dirname+'/Tiff/another.tiff').append(false);

could i add the tiff with one page into the tiiff with three pages and get a one tiff file with four pages?

So_oP
  • 1,211
  • 15
  • 31
  • Your question is not very clear. Do you mean you have `file1.tif` and `file2.tif` and `file3.tif`? Or do you mean you have `file.tif` and it contains three pages? – Mark Setchell Feb 01 '17 at 11:56
  • Sorry if i didi not write clear.I mean that i have file1.tiff which have 1 page, and have file2.tiff which have 3 pages.so in final result i would like to have one tiff file with 4 pages.But i do not want to create a new file, just add the single page tiff into tiff which have 3 pages. In other words i would like to append file1.tiff with file2.tiff and as a result get one tiff file with 4 pages. – So_oP Feb 01 '17 at 12:15

3 Answers3

1

Your question is quite unclear, so I will show you some examples and you can extract the bits you need.

Let's say we start with a single TIFF file, called 6page.tif, that has 6 pages in it. Let's see how many pages there are:

gm identify 6page.tif
6page.tif[0] TIFF 595x842+0+0 DirectClass 16-bit 17.2Mi 0.000u 0m:0.000000s
6page.tif[1] TIFF 595x842+0+0 DirectClass 16-bit 17.2Mi 0.000u 0m:0.000000s
6page.tif[2] TIFF 595x842+0+0 DirectClass 16-bit 17.2Mi 0.000u 0m:0.000000s
6page.tif[3] TIFF 595x842+0+0 DirectClass 16-bit 17.2Mi 0.000u 0m:0.000000s
6page.tif[4] TIFF 595x842+0+0 DirectClass 16-bit 17.2Mi 0.000u 0m:0.000000s
6page.tif[5] TIFF 595x842+0+0 DirectClass 16-bit 17.2Mi 0.000u 0m:0.000000s

Ok, 6 pages, numbered 0-5.

Let's extract page 3 to a PNG:

gm convert 6page.tif[3] JustPage3.png

Let's append the extracted page 3 to the end of the original tif:

gm convert 6page.tif JustPage3.png BigBoy.tif

Now check what we have got - yes, 7 pages:

gm identify BigBoy.tif
BigBoy.tif[0] TIFF 595x842+0+0 DirectClass 16-bit 17.7Mi 0.000u 0m:0.000000s
BigBoy.tif[1] TIFF 595x842+0+0 DirectClass 16-bit 17.7Mi 0.000u 0m:0.000000s
BigBoy.tif[2] TIFF 595x842+0+0 DirectClass 16-bit 17.7Mi 0.000u 0m:0.000000s
BigBoy.tif[3] TIFF 595x842+0+0 DirectClass 16-bit 17.7Mi 0.000u 0m:0.000000s
BigBoy.tif[4] TIFF 595x842+0+0 DirectClass 16-bit 17.7Mi 0.000u 0m:0.000000s
BigBoy.tif[5] TIFF 595x842+0+0 DirectClass 16-bit 17.7Mi 0.000u 0m:0.000000s
BigBoy.tif[6] TIFF 595x842+0+0 PseudoClass 65536c 16-bit 17.7Mi 0.000u 0m:0.000000s
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • oh thank you! but how i can do this functionality with node js code instead of cmd command?i mean that all this action i would like to perform through node js not through cmd?is it possible??sorry i just newbee in node and sometimes i can give obvious questions – So_oP Feb 01 '17 at 13:33
0

The imagemagick command is convert images.tiff image%02d.png.

I'm not familiar with the gm module; I would just use child_process for this.

OrangeDog
  • 36,653
  • 12
  • 122
  • 207
0

Take a look this npm module https://www.npmjs.com/package/gm

Also this documentation especially the part of adjoin function

http://aheckmann.github.io/gm/docs.html

From documentation about adjoin function.

join images into a single multi-image file By default, all images of an image sequence are stored in the same file. However, some formats (e.g. JPEG) do not support storing more than one image per file and only the first frame in an image sequence will be saved unless the result is saved to separate files. Use +adjoin to force saving multiple frames to multiple numbered files. If +adjoin is used, then the output filename must include a printf style formatting specification for the numeric part of the filename.

NeoXX
  • 135
  • 3
  • 12