|
@ -15,11 +15,14 @@ img.onerror = function(err){ |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
img.onload = function(){ |
|
|
img.onload = function(){ |
|
|
var width = img.width / 2 |
|
|
var width = 100; |
|
|
, height = img.height / 2 |
|
|
var height = 100; |
|
|
, canvas = new Canvas(width, height) |
|
|
var canvas = new Canvas(width, height); |
|
|
, ctx = canvas.getContext('2d'); |
|
|
var ctx = canvas.getContext('2d'); |
|
|
|
|
|
|
|
|
|
|
|
ctx.imageSmoothingEnabled = true; |
|
|
ctx.drawImage(img, 0, 0, width, height); |
|
|
ctx.drawImage(img, 0, 0, width, height); |
|
|
|
|
|
|
|
|
canvas.toBuffer(function(err, buf){ |
|
|
canvas.toBuffer(function(err, buf){ |
|
|
fs.writeFile(__dirname + '/resize.png', buf, function(){ |
|
|
fs.writeFile(__dirname + '/resize.png', buf, function(){ |
|
|
console.log('Resized and saved in %dms', new Date - start); |
|
|
console.log('Resized and saved in %dms', new Date - start); |
|
@ -27,5 +30,5 @@ img.onload = function(){ |
|
|
}); |
|
|
}); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
img.src = __dirname + '/images/squid.png'; |
|
|
img.src = process.argv[2] || __dirname + '/images/squid.png'; |
|
|
|
|
|
|
|
|