0

I used this function to get the ratio width/height of a photo to assign automatic values of portrait or lanscape:

    var newimage = new Image();
    newimage.src = ImageDir; //Directory of my image
    newimage.onload = function ratio()
{
    var width = this.naturalWidth;
    var height = this.naturalHeight;
    var divi = (width/height);
    return divi.value;
}
alert(divi)

Will return the correct value, but I want to in corporate this code:

if (divi > 1) {
        node.getElementById("myImage"+"-"+nump).dataset.size = ("1600x1200");
    } else {
        node.getElementById("myImage"+"-"+nump).dataset.size = ("1200x1600");
}

I tried someting like this:

var newimage = new Image();
    newimage.src = ImageDir; //Directory of my image
    newimage.onload = function ratio()
{
    var width = this.naturalWidth;
    var height = this.naturalHeight;
    var divi = (width/height);
    if (divi > 1) {
        node.getElementById("myImage"+"-"+nump).dataset.size = ("1600x1200"); //nump is the number of repetitions the While loop as been in (for increments)
    } else {
        node.getElementById("myImage"+"-"+nump).dataset.size = ("1200x1600");
}
}

But the values of if and else won't output... They do if I put them out of the first function. This is all in a While loop, so the divi variable will change everytime.

Can someone help me get that Divi value for my If condition? Thank you!

0 Answers0