neocotic / convert-svg

Node.js packages for converting SVG into other formats using headless Chromium
MIT License
200 stars 47 forks source link

Convert SVG buffer to PNG buffer? #16

Closed danielnjoo closed 7 years ago

danielnjoo commented 7 years ago

Question more than issue: I'm trying to post a PNG to AWS S3 without writing locally, AWS accepts buffers and that's what I thought convert outputs. However, when I use convert and then try to PUT the resulting object into AWS, I get an error indicating that it's not a buffer? Expected params.Body to be a string, Buffer, Stream, Blob, or typed array object

var body = new Buffer(svgString);
const Converter = require('convert-svg-to-png');
const png = Converter.convert(body, {height:600},{width:600});

Am I using convert wrongly?

neocotic commented 7 years ago

@danielnjoo You are correct that the convert methods output a PNG buffer, however, these methods are asynchronous and return a Promise that is resolved with the buffer once conversion is complete.

You can use the Promise API directly or ES2017's async/await syntax to get the buffer.

I hope this helps.

danielnjoo commented 7 years ago

Thanks, totally solved my problem :)