I used the canvas tag to crop my image.
as following my code:
autoCropImage(url){
var img = new Image();
const cropApp = this;
let x = img.onload = function(){
var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
const center_X = img.width/2, center_Y = img.height/2;
let init_X=0, init_Y=0;
ctx.drawImage(img, init_X, init_Y, img.width, img.height, 0, 0, img.width, img.height);
let dataUrl = canvas.toDataURL("image/jpeg", 1.0);
let dataUrl_short = dataUrl.replace("data:image/jpeg;base64,", "");
return dataUrl;
}();
img.src=url;
console.log(x);
return x;
}
//log result:
//data:,
I consider the log result should be a string of base64, but the callback is data:,
What's the problem in my code?