Search code examples
node.jspngtiffimagemagick-convert

Tiff convert to png Node js


i have to convert multiple tiff to png. For example tiff which include 3 pages i should convert to 3 png's.So i am using tiff-to-png module and i have encountered with this problem. Error: Command failed: convert /tiffs/one.tiff -scene 1 ./png/one/page%d.png Invalid Parameter - /tiffs.Bellow is my code

'use strict'

const tiff_to_png=require('tiff-to-png');

const options={
  logLevel:1
};

const converter=new tiff_to_png(options);

const tiffsLocation=['./tiffs/one.tiff'];
const location='./png';

converter.convertArray(tiffsLocation,location);

In the error context we see -/tiffs inavliiad parameter.

tiffsLocation is the variable which conatin my tiff file.

location is variable which contain path to folder where will be converted png file.

I cant understand why i have goten this error, tiffs in this case is the directory which contain my tiff file why i have got this error.Any ideas?


Solution

  • 1st You have to install "Imagemagick"

    1. For windows, you will find .exe file. Keep it in your mind that on installation time, check "Install legacy utilities (e.g: convert)"

    2. For Ubuntu:

    sudo apt install imagemagick

    1. For Cent OS:

    sudo yum install ImageMagick

    var fs=require('fs');
    var spawn = require('child_process').spawn;
    //ifile: Tiff Absolute File Path
    //ofile: PNG Absolute File Path (e.g: var ofile = APP_ROOT_PATH+'/data/files/png/sample.png';)
    var tiff2png = spawn('convert', [ifile, ofile]);
    tiff2png.stdout.on('data', function (data) {
        console.log('stdout: ' + data);
    });
    tiff2png.stderr.on('data', function (data) {
        return res.json(Utility.output('Unable to convert tiff to png','ERROR'));
        console.log('stderr: ' + data);
    });
    tiff2png.on('close', function (code) {
        /**Check Your Converted file exist or not. If exist then Converted**/
        console.log('Close: ' + data);
    });
    tiff2png.on('error', function (code) {
        return res.json(Utility.output('ERROR: Unable to convert tiff to png','ERROR'));
    });