Image.onload function returns zero for height and width
<pre><code>var icon1 = new Image();
var wid1;
var hei1;
icon1.onload = function () {
    wid1 = icon1.width;
    hei1 = icon1.height;
};
icon1.src = resource;
var rati = wid1 / hei1;
</code></pre>

<p>What I am trying to do is to get the width and height of the image and then calculate the ratio that will further help to maintain the aspect ratio of the image. </p>

<p>But when I run this code, lot of times I get the width and height of image as <code>0</code> that will result turning ratio to <code>NaN</code> and finally the image never loads because of <code>0</code> height and width. Any Help?</p>
