javascript - Trouble using `child_process` to convert svg to png -


i inherited node.js project who's graph broken.

the graph function using "d3": "^3.5.2" , hanging on require.

i dug around , found problem contextify , jsdom , found solution. no longer hangs it's not writing graph correctly.

it's using child_process convert svg png , result weird, tiny vertical line.

i've posted code below (redacting meat of draw function brevity).

if uncomment for debugging lines graph displays perfectly, it's losing in conversion.

this kind of new me , i'm in bit of time crunch hoping see if spots glaring problem or can point me in right direction.

any appreciated.

stashmodel.afterremote('prototype.datapointsgraph', function (ctx, unused, next) {   var res = ctx.res,       req = ctx.req,       fs = require('fs'),       storageservice = require('loopback-component-storage').storageservice,       handler = new storageservice({provider: 'filesystem', root: res.locals.filepathroot}),       child_proc = require('child_process'),       convert = child_proc.spawn("convert", ["svg:", "png:-"]);    var d3 = require('d3'),       jsdom = require('jsdom');    var document = jsdom.jsdom();    drawwaveformgraph = function (rawdata, pointformatcb) {     //this large , glorious function returns     //the graph svg     return d3.select(document.body).node().innerhtml;   };    convert.stdout.on('data', function (data) {     res.write(data);   });    convert.stderr.on('data', function (data) {     console.log(data);   });    convert.on('exit', function (code) {     res.end();   });    var filename = res.locals.fileabspath;   fs.exists(filename, function(exists) {     if (exists) {       fs.stat(filename, function(error, stats) {         fs.open(filename, "r", function(error, fd) {           var buffer = new buffer(stats.size);           fs.read(fd, buffer, 0, buffer.length, null, function(error, bytesread, buffer) {              var csv = buffer.tostring("utf8", 0, buffer.length).split('\n');             var svg = drawwaveformgraph(csv, function (record) {               var fields = record.split(',');               return {                 time: math.floor(parseint(fields[0], 10)/1000000),                 xaccel: parsefloat(fields[1]),                 yaccel: parsefloat(fields[2])               };             });              // debugging             // res.write('<html><body>' + svg + '</body></html>');             // res.end();              res.set({'content-type': 'image/png'});             convert.stdin.write(svg);             convert.stdin.end();              fs.close(fd);           });         });       });     }   });  }); 

**********edit*************

i'm getting errors in convert.stderr.on('data') function. are:

convert: unable read font `(null)' @ error/annotate.c/renderfreetype/1315.

convert: non-conforming drawing primitive definition `text' @ error/draw.c/drawimage/3169.


Comments