1

How to adapt this solution (code from here: https://stackoverflow.com/a/626505/975443)

var img = new Image();
img.onload = function() {
  alert(this.width + 'x' + this.height);
}
img.src = 'http://www.google.com/intl/en_ALL/images/logo.gif';

for multiple images (for loop through an array)?

Community
  • 1
  • 1
Kozuch
  • 2,272
  • 3
  • 26
  • 38

2 Answers2

2

Solution:

var asyncI = 0;
var asyncCount = 10;

function readImageDimensions() {

    console.log('asyncI: ' + asyncI);

    var img = new Image();
    img.src = 'data/images/' + asyncI + ".png";

    img.onload = function() {

        console.log('this.width: ' + this.width + ', this.height: ' + this.height);

        asyncI++;

        if (asyncI < asyncCount) {

            //go to next loop iteration
            console.log('continue ' + asyncI);
            readImageDimensions();

        } else {

            //exit loop
            console.log('END');
            functionToContinueWith();

        }
    }
}

//call the function
readImageDimensions();
Kozuch
  • 2,272
  • 3
  • 26
  • 38
0

this may help you

      for (var i=0;i<number_of_photos;i++){ 
widthheight[i]=width + 'x' + height
}

alert first one via alert(widthheight[0]);

because i'm not familiar with your code & i dont know what you really want cant help more

are you using jquery ?

Pooya Estakhri
  • 1,129
  • 1
  • 11
  • 25