使用node.js npm canvas?
可以'在图像中填充模式'我尝试了以下方式。但是我收到了错误
返回新的CanvasPattern(图片); ^ 错误:给定的图像尚未完成加载。
exports.convertImg = function(story){
var Canvas = require('canvas')
, canvas = new Canvas(200,200)
, ctx = canvas.getContext('2d'),textDimensions, img = new Canvas.Image;
var textWidth = ctx.measureText(story).width;
img.src = "/images/fillimage.png";
var buffer = new Buffer(story, "base64"),length=buffer.length;
var pat=ctx.createPattern(img,"repeat");
ctx.fillStyle = pat;
ctx.font = "20px verdana";
var x= (canvas.width -200) / 2;
var y= 60;
wrapText(ctx,story,x,y,200,200);
var imges = canvas.toDataURL();
var data = imges.replace(/^data:image\/\w+;base64,/, "");
var buf = new Buffer(data, 'base64');
var length=buf.length;
return images;
}
如何在canvas fillpattern中填充背景图像。请帮助我。
感谢。