I'm trying to get the width and height of an image using its src URL.
This code outputs "undefinedxundefined" to the console.
This is what I have now:
getImageSize(image: string) {
let width;
let height;
let img = new Image();
img.src = image;
img.onload = function (event) {
let targetImg = event.currentTarget as HTMLImageElement;
width = targetImg.width;
height = targetImg.height
}
return width + "x" + height;
}
I'm using Angular version 12.2.11.