I'm trying to scale a local image through Javascript like this:
function resizeImage(file, func){
var canvas = document.createElement('canvas');
var img = new Image();
img.onload = function () {
var factor = img.width/800;
canvas.width = 800;
canvas.height = img.height/factor;
ctx = canvas.getContext('2d');
ctx.scale(factor, factor);
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
func(canvas.toDataURL());
}
img.src = file.dataload; //file is an json-Object and dataload a dataURI
}
Somehow the data returned by canvas.toDataURL() is not resized in any way. I double checked that canvas.width and canvas.height are the correct computed sizes.
Any idea what goes wrong?