Browse Source

tweak crop.js example slightly

v1.x
Tj Holowaychuk 13 years ago
parent
commit
3c7e747f04
  1. 19
      examples/crop.js

19
examples/crop.js

@ -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';

Loading…
Cancel
Save