Possible Duplicate:
Determine original size of image cross browser?
jquery get image size
could someone tell me how do i get the real size of an image using JS / JQ ?
THX !
tried a lot of solutions from this site but no success…
var selector = $(".album_pics > img[id="+img_id+"]") ;
var old_width = selector.width() ;
Doesnt work..
You can use the
naturalWidthproperty:JS Fiddle demo.
This does, of course, require that the image has time to load before the JavaScript is executed (so, in jQuery, using the
$(window).load()method). It is, also, HTML5-only (which I hadn’t realised until I checked, just now).Incidentally, as perhaps the name implies, there’s also the
naturalHeightproperty (if that would be of use).Updated to add a slightly more functional approach:
JS Fiddle demo.
References:
naturalWidth.