I think it would be better if you use JQuery to get the height and width, as it works fine in all browsers, so your code would be something like this :-
$(document).ready(function() {
var imgs = $('img');
var imgLength = imgs.length;
for(var i=0; i<= imgLength-1;i++){
var imgWidth = imgs[i].width();
var imgHeight = imgs[i].height();
$('img').eq(i).attr({width:imgWidth, height: imgHeight});
console.log(imgWidth);
}
console.log(imgLength);
});