I'm working with a plugin that requires me to get the width and height of the image, after it's loaded, regardless of how the dimensions of the image were determined.
<img src=".." width="500" height="500" /> <!-- works fine -->
<img src=".." style="width: 500px; height: 500px;" /> <!-- works fine -->
<img src=".." width="500" /> <!-- only gives me width -->
<img src=".." style="width: 500px;" /> <!-- only gives me width -->
<img src=".." style="width: 500px; height: auto;" /> <!-- only gives me width -->
<img src=".." /> <!-- doesn't work at all -->
I have tried loading the image and getting its dimensions after but i've only been able to get the image's actual size and not the size at which it is display on the page.
The code im using to get the width/height:
img.innerWidth();
I Have also tried:
$('<img/>').hide().attr('src',img.src).load(function() {
img.Owidth = $(this).width();
img.Oheight = $(this).height();
}).appendTo($('body'));
And:
$("<img/>").attr("src", img.attr("src")).load(function() {
img.width = this.width;
img.height = this.height;
});
Which do a fine job at getting me the original size of the image, but not the size of when it's loaded and displayed.