是的,我在 Nodejs 中做到了,但在 PhantomJS 中不行。
imgContent = '...base64...string';
imgContent = imgContent.replace(/^data:image\/png;base64,/, "");
chart_path = "/charts.png";
fs.write(chart_path, new Buffer(imgContent, 'base64'), 'w');
错误信息:
ReferenceError:找不到变量:缓冲区
最佳答案
我不确定这是否是最好的解决方案,但它对我来说效果很好。
// ...
fs.write(chart_path, atob(imgContent), 'b');
Phantomjs 版本 2.1.1。
关于javascript - phantomjs:将base64字符串保存为文件(png),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42558571/