Browse Source

added image-src.js example

draw the canvas intself back via drawImage()
v1.x
Tj Holowaychuk 14 years ago
parent
commit
5af34793fe
  1. 40
      examples/image-src.js

40
examples/image-src.js

@ -0,0 +1,40 @@
/**
* Module dependencies.
*/
var Canvas = require('../lib/canvas')
, Image = Canvas.Image
, canvas = new Canvas(200, 200)
, ctx = canvas.getContext('2d')
, fs = require('fs');
ctx.fillRect(0,0,150,150);
ctx.save();
ctx.fillStyle = '#09F'
ctx.fillRect(15,15,120,120);
ctx.save();
ctx.fillStyle = '#FFF'
ctx.globalAlpha = 0.5;
ctx.fillRect(30,30,90,90);
ctx.restore();
ctx.fillRect(45,45,60,60);
ctx.restore();
ctx.fillRect(60,60,30,30);
var img = new Image;
img.src = canvas.toBuffer();
ctx.drawImage(img, 0, 0, 50, 50);
ctx.drawImage(img, 50, 0, 50, 50);
ctx.drawImage(img, 100, 0, 50, 50);
var out = fs.createWriteStream(__dirname + '/image-src.png')
, stream = canvas.createPNGStream();
stream.on('data', function(chunk){
out.write(chunk);
});
Loading…
Cancel
Save