var crop = function(canvas, offsetX, offsetY, width, height, callback) {
var buffer = document.createElement('canvas');
var b_ctx = buffer.getContext('2d');
buffer.width = width;
buffer.height = height;
b_ctx.drawImage(canvas, offsetX, offsetY, width, height,
0, 0, buffer.width, buffer.height);
callback(buffer.toDataURL());
};
var canvas = document.getElementById('main');
var img = new Image();
img.crossOrigin = "Anonymous";
img.onload = function() {
canvas.width = this.width;
canvas.height = this.height;
canvas.getContext('2d').drawImage(this, 0, 0);
setTimeout(function() {
crop(canvas, 100, 70, 70, 70, callback)
}, 1000);
};
img.src = "https://dl.dropboxusercontent.com/s/1alt1303g9zpemd/UFBxY.png";
var callback = function(dataURL) {
document.body.style.backgroundImage = 'url(' + dataURL + ')';
}