一个常见的需求。
知乎上得讨论:http://www.zhihu.com/question/32156977
node-canvas 在mac上安装有问题,可能是我没有sudo
使用了ccap:挺不错的。
简单例子:http://snoopyxdy.blog.163.com/blog/static/60117440201301842110923/
github:https://github.com/Automattic/node-canvas
安装:node install ccap
var express = require('express');
var router = express.Router();
var ccap = require('ccap')();
var util = require('util'); /* GET home page. */
router.get('/', function(req, res, next) {
// res.render('index', { title: 'Express' });
res.render('index.html');
}); router.get('/test', function(req, res, next) { var ary = ccap.get(); var txt = ary[0]; var buf = ary[1]; res.end(buf); console.log(util.inspect({buf:buf})); console.log(txt); // res.render('index', { title: 'Express' });
// res.render('index.html');
}); module.exports = router;
最后采用了ccap
官网:https://github.com/DoubleSpout/ccap
linux下安装时,需要安装gcc:apt-get install gcc