I am trying to compress image size using JavaScript. but it returns canvas error. below is my code.
var reader = new FileReader();
reader.readAsDat
You might have to resize the canvas size
refer the following example here
function resizeImg(base, width, height) {
var canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
var context = canvas.getContext("2d");
var deferred = $.Deferred();
$("").attr("src", "data:image/gif;base," + base).load(function() {
context.scale(width/this.width, height/this.height);
context.drawImage(this, 0, 0);
deferred.resolve($("").attr("src", canvas.toDataURL()));
});
return deferred.promise();
}