问题
I'm trying to use imagemagick to convert svgs to pngs, rescale them and put them in a response stream.
I'm using https://www.npmjs.com/package/imagemagick like this:
var imageUri = __dirname + '/images/' + project + '/' + image + '.svg';
console.log(imageUri);
var svg = fs.readFileSync(imageUri, 'utf8');
res.writeHead(200, {'Content-Type': 'image/png' });
var size = '' + (100 * scale);
var conv = im.convert(['svg:-', '-resize', size + 'x' + size, 'png:-']);
conv.on('data', function(data) {
res.write(data, 'binary');
});
conv.on('end', function() {
res.end();
});
conv.stdin.write(svg);
conv.stdin.end();
Only problem is that it adds a background when I was hoping for something transparent. Any ideas of how I can fix this?
来源:https://stackoverflow.com/questions/33435877/nodejs-imagemagick-converting-svg-to-png-adds-a-white-background-how-to-keep-it