是否有更好的方式将图片发送给客户?
base64太慢了。
这是github
https://github.com/abnerCrack/screenshot
服务器
exec("phantomjs screen.js " + this.query.url + " " + this.query.width + " " + this.query.width,options,function (error, stdout, stderr) {
if(error) console.log("Error:", error);
callback(null, "data:image/png;base64," + stdout);
console.log(stdout,stderr)
});
}
// response
app.route('/query')
.get(function * (next) {
console.log("query", this.query);
this.body = yield screenshot;
});
screen.js
page.onLoadFinished = function(status) {
var base64 = page.renderBase64('JPEG');
if (status !== 'success') {
console.log('request fail');
} else {
console.log(base64);
}
phantom.exit();
};
page.open(args[1]);