I'm using Papa Parse to parse a local CSV file.
When I print my updated objects to the console, I get the object to return with the changed values I have applied based on certain conditions.
My problem is getting the image dimensions: Width and Height.
Below is my script;
var w;
var h;
let testString = "s2345232";
if (/^[s]\d+$/.test(testString) == true) {
url = baseUrl + testString + suffix;
getMeta(url, function(width, height) {
w = width;
h = height;
console.log(w, h); //works
});
}
console.log(w, h); // doesn't work
// Here is the function to retrieve the image data
function getMeta(url, callback) {
var img = new Image();
img.src = url;
img.addEventListener("load", function() {
callback(this.naturalWidth, this.naturalHeight);
});
};
What am I doing wrong and how can I fix it?