JV10
JV10

Reputation: 891

How to get the width and height of a dynamically loaded image?

How do I get the width and height of a dynamically loaded image?

<img id="thumb_320" src="dscn6691_thumb_320.jpg">

Upvotes: 0

Views: 2165

Answers (1)

Alastair Pitts
Alastair Pitts

Reputation: 19601

try using the Image object. I'm honestly not sure of compatability though.

so some code might look like:

var img = new Image();

img.onload = function(){
    alert('Width: ' + img.width +', Height: ' + img.height);
}

img.src = 'http://www.google.com/images/logos/ps_logo2.png';

Example: http://jsfiddle.net/EQdxw/2/

Upvotes: 4

Related Questions