From b2179920e3de37513c14d58da4ab7d2dc5573266 Mon Sep 17 00:00:00 2001 From: Tj Holowaychuk Date: Wed, 3 Nov 2010 14:30:47 -0700 Subject: [PATCH] gradients example using streaming api --- examples/gradients.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/examples/gradients.js b/examples/gradients.js index 3bbb880..70ac649 100644 --- a/examples/gradients.js +++ b/examples/gradients.js @@ -5,7 +5,8 @@ var Canvas = require('../lib/canvas') , canvas = new Canvas(320, 320) - , ctx = canvas.getContext('2d'); + , ctx = canvas.getContext('2d') + , fs = require('fs'); // Create gradients var lingrad = ctx.createLinearGradient(0,0,0,150); @@ -26,4 +27,9 @@ ctx.strokeStyle = lingrad2; ctx.fillRect(10,10,130,130); ctx.strokeRect(50,50,50,50); -canvas.savePNG(__dirname + '/gradients.png'); \ No newline at end of file +var out = fs.createWriteStream(__dirname + '/gradients.png') + , stream = canvas.createPNGStream(); + +stream.on('data', function(chunk){ + out.write(chunk); +}); \ No newline at end of file