index.js
function (imgsrc, width, height, callback) {
    var args = new Args(arguments);
    checkCommonArgs(args);

    var Image = Canvas.Image, fs = require("fs");
    var img = new Image();
    img.onerror = function(err) {
        callback(false, err);
    };
    img.onload = function() {
        var w = img.width;
        var h = img.height;
        var newx = Math.abs(w / 2 - width / 2);
        var newy = Math.abs(h / 2 - height / 2);
        var canvas = new Canvas(width, height);
        var ctx = canvas.getContext("2d");
        ctx.drawImage(img, newx, newy, width, height, 0, 0, width, height);
        callback(true, canvas);
    };
    if (!isValidFile(imgsrc)) {
        callback(false, new Error (imgsrc + ' is not a valid file'));
    } else {
        img.src = imgsrc;
    }
}
function (imgsrc, width, height, callback) {
    var args = new Args(arguments);
    checkCommonArgs(args);

    var Image = Canvas.Image, fs = require("fs");
    var img = new Image();
    img.onerror = function(err) {
        callback(false, err);
    };
    img.onload = function() {
        var w = img.width;
        var h = img.height;
        var newx = Math.abs(w / 2 - width / 2);
        var newy = Math.abs(h / 2 - height / 2);
        var canvas = new Canvas(width, height);
        var ctx = canvas.getContext("2d");
        ctx.drawImage(img, newx, newy, width, height, 0, 0, width, height);
        callback(true, canvas);
    };
    if (!isValidFile(imgsrc)) {
        callback(false, new Error (imgsrc + ' is not a valid file'));
    } else {
        img.src = imgsrc;
    }
}
function ( imgsrc , width , height , callback ) { var args = new Args ( arguments ) ; checkCommonArgs ( args ) ; var Image = Canvas . Image , fs = require ( "fs" ) ; var img = new Image ( ) ; img . onerror = function ( err ) { callback ( false , err ) ; } ; img . onload = function ( ) { var w = img . width ; var h = img . height ; var newx = Math . abs ( w / 2 - width / 2 ) ; var newy = Math . abs ( h / 2 - height / 2 ) ; var canvas = new Canvas ( width , height ) ; var ctx = canvas . getContext ( "2d" ) ; ctx . drawImage ( img , newx , newy , width , height , 0 , 0 , width , height ) ; callback ( true , canvas ) ; } ; if ( ! isValidFile ( imgsrc ) ) { callback ( false , new Error ( imgsrc + ' is not a valid file' ) ) ; } else { img . src = imgsrc ; } }
Crops an image to bounds specified by width and height
imgsrc - string path to image to crop
width - integer width of cropped image
height - integer height of cropped image
callback - callback function(
result - boolean true on success
data - canvas object on success, Error on failure
Crops an image to bounds specified by width and height imgsrc - string path to image to crop width - integer width of cropped image height - integer height of cropped image callback - callback function ( result - boolean true on success data - canvas object on success Error on failure