Reputation: 329
My main goal is to convert an SVG tag to PNG using Node.js and ImageMagick. I am also caching data to a Transform
stream that writes to a file. I have the SVG tag ready, and when I either console.log
or process.stdout.write
anything in the _transform
function, nothing is outputted on my terminal.
let streamer = new Transform()
streamer._transform = function(data, enc, cb) {
stdout.write('Does this even run?') // or console.log
stdout.write(data)
fileWriter.write(data)
this.push(data)
cb()
}
let svgToPng = cp.spawn('convert', ["svg:", "png:-"])
svgToPng.stdout.pipe(streamer).pipe(res)
let svgStr = `<svg>` + svg.node().innerHTML + `</svg>`
svgToPng.stdin.write(svgStr, (err) => {
console.log(err) // null
}) // svgStr is valid SVG
svgToPng.stdin.end()
Now spawn
does not make a new node
process but makes a POSIX
process I believe and couldn't really figure out how to debug the a POSIX
process from VSCode or a Node
process in general.
I know that the correct way to convert an SVG to PNG via ImageMagick solely is
echo SVG_INNERHTML | convert svg:- png:-
I have a feeling that spawn
does not automatically do echo
which is kind of vital and that it does
SVG_INNERHTML | convert svg:- png:-
Again these are just my predictions, all I want to do is convert an SVG to PNG via imageMagick.
Any explanation (or even just how to debug this) would be great.
Upvotes: 1
Views: 16