Search code examples
node.jsgraphicsmagick

Converting EPS to PNG using graphicsmagic for node does not keep transparency


I've been trying to convert a transparent EPS file to a transparent PNG file using graphicsmagic for node (http://aheckmann.github.io/gm/).

It needs to behave the same way as the following command (preserving transparency of the EPS)

convert -colorspace srgb in.eps out.png

The above command works as expected but when I try it in node with the following code it does not retain transparency.

var gm = require('gm').subClass({ imageMagick: true });

gm("in.eps").colorspace("srgb").write("out.png", function (err) {
  if (!err) {
    console.log('done');
  }
});

I've also tried forcing the type TrueColorAlpha and setting the bit depth but to no avail.

Hopefully someone van advise on what I'm doing wrong or which information I'm missing.


Solution

  • For anyone stumbling upon this problem as well, this solved it for me.

    var gm = require('gm').subClass({ imageMagick: true });
    
    gm("in.eps").in("-colorspace").in("srgb").write("out.png", function (err) {
      if (!err) {
        console.log('done');
      }
    });
    

    You need to add two custom in parameters to apply colorspace to the input EPS image.