I'm working with react and I'm trying to get the height and width from an image from which I only have the url. This is what I have so far:
const testImg = new Image();
let a; let b;
testImg.addEventListener("load", function(){
console.log("1. Properties " + testImg.width + " " + testImg.height);
a = testImg.width;
b = testImg.height;
});
testImg.src = thumbUrl;
console.log("2. Properties " + testImg.width + " " + testImg.height);
console.log("3. Properties " + a + " " + b);
The output of the first "properties" log is correct (336 & 223 pixels). The output of the second is 0 & 0 and the output of the third is undefined & undefined.
I have tried puting the "testImg.src = thumbUrl" line before the onload function and the outputs are the same. I need to use these values outside that function. Also have tried using the decode function.
If you have any other approach or a solution for this I'd appreciate that very much.