Search code examples
node.jsimage-processinggraphicsmagickformat-conversion

How to convert filetype using GraphicsMagick for node.js


How do you "Convert" a file from one type to another using gm? (e.g .png > .jpg)

I found this but it doesn't seem that the node.js version has the same method:


Solution

  • You'll need to change the format of the output file.

    var writeStream = fs.createWriteStream("output.jpg");
    gm("img.png").setFormat("jpg").write(writeStream, function(error){
        console.log("Finished saving", error);
    });
    

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