-1

I am using graphicsmagick npm:

https://www.npmjs.com/package/gm
I am trying to write a code like the following.
I am trying to make this work with stream ...
myimg.png is an image with white background.
I want to change the white background to transparent as stated in the npm docs using -transparent.
const gm = require('gm');
const fs = require('fs');

// ....

function makeTransparent(){
     const readStream = fs.createStream("myimg.png");
     gm(readStream)
          .transparent("#FFFFFF")
          .stream(function, err, stdout, stderr) {
              const writeStream  = fs.createWriteStream("result.png");
              stdout.pipe(writeStream);
          });
}

What am I doing wrong here?

user12822357
  • 21
  • 1
  • 4

1 Answers1

0

you have a lot of typos, you need to require your packages as well:

var fs = require('fs')
    , gm = require('gm');
const readStream = fs.createReadStream("myimg.jpg");
gm(readStream)
    .transparent("#FFFFFF")
    .stream(function (err, stdout, stderr) {
        const writeSTream = fs.createWriteStream("result.png");
        stdout.pipe(writeSTream);
    });
Sunil Lama
  • 4,531
  • 1
  • 18
  • 46