node.js canvas图片作为'背景'

时间:2014-07-03 06:10:39

标签: html5 node.js canvas

使用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中填充背景图像。请帮助我。

感谢。

0 个答案:

没有答案