我想使用node-canvas生成并提供.png文件。使用Express,这是我到目前为止所做的:
draw_badge.js
function draw() {
var Canvas = require('canvas'),
Image = Canvas.Image,
canvas = new Canvas(200, 200),
ctx = canvas.getContext('2d');
ctx.font = '30px Impact';
ctx.rotate(0.1);
ctx.fillText('Awesome!', 50, 100);
return canvas;
}
module.exports = draw;
badge.js
var express = require('express');
var router = express.Router();
var draw = require('../lib/draw_badge.js');
router.get('/show', function (req, res, next) {
res.setHeader('Content-Type', 'image/png');
res.end(draw());
});
module.exports = router;
但是当我在浏览器中访问该路线时,我看不到任何png。我对节点的掌握不够牢固,无法理解发生了什么。有人能指出我正确的方向吗?