Permalink
Browse files

tweak crop.js example slightly

  • Loading branch information...
tj committed Jan 14, 2012
1 parent d284e48 commit 3c7e747f04bb3a370ce95413b35c3f7e87c81daa
Showing with 7 additions and 12 deletions.
  1. +7 −12 examples/crop.js
View
@@ -7,8 +7,7 @@ var Canvas = require('../lib/canvas')
, Image = Canvas.Image
, fs = require('fs');
var img = new Image
, start = new Date;
var img = new Image;
img.onerror = function(err){
throw err;
@@ -19,21 +18,17 @@ img.onload = function(){
, h = img.height / 2
, canvas = new Canvas(w, h)
, ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0, w, h, 0, 0, w, h);
var out = fs.createWriteStream(__dirname + '/crop.jpg')
, stream = canvas.createJPEGStream({
bufsize : 2048,
quality : 80
});
var out = fs.createWriteStream(__dirname + '/crop.jpg');
stream.on('data', function(chunk, len){
out.write(chunk);
var stream = canvas.createJPEGStream({
bufsize : 2048,
quality : 80
});
stream.on('end', function(){
console.log('Cropped and saved in %dms', new Date - start);
});
stream.pipe(out);
};
img.src = __dirname + '/images/squid.png';

0 comments on commit 3c7e747

Please sign in to comment.