1

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?

nyedidikeke
  • 6,899
  • 7
  • 44
  • 59
Ish Sah.
  • 43
  • 3

2 Answers2

1

Just using newHeader1 = 'Size'

Devil
  • 21
  • 2
  • Thanks that was the issue. Changed it but now having trouble with image dimensions and storing them into global variables. – Ish Sah. May 08 '19 at 13:46
0

There's a problem with the way you generate the header rows for your new columns. Papa expects each row to have the same column names, but by specifying newHeader1 = propString + "_Size" etc, it means the column names will be different. Could you just use a constant for each column name? E.g. newHeader1 = "Size".

Jaybird
  • 541
  • 4
  • 13