replaced img.attr('height') with img.height()

first returned undefined, because the height referes to the css property
and not the dom element