I have a image resizer function that resize images proportional. On every image load a call this function with image and resize if its width or height is bigger than my max width and max height. I can get img.width and img.height in FF Chrome Opera Safari but IE fails. How can i handle this?
Let me explain with a piece of code.
<img src="images/img01.png" onload="window.onImageLoad(this, 120, 120)" /> function onImageLoad(img, maxWidth, maxHeight) { var width = img.width; // Problem is in here var height = img.height // Problem is in here }
In my highligted lines img.width don't work on IE series.
Any suggestion?
Thanks.
Don't use width
and height
. Use naturalWidth
and naturalHeight
instead. These provide the image unscaled pixel dimensions from the image file and will work across browsers.