Tj Holowaychuk
14 years ago
1 changed files with 40 additions and 0 deletions
@ -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…
Reference in new issue