now i get the image's width and height when onload function of img . my problem is, the image original width = 500px but document.getElementId(id).offsetWidth gives only 300px and also for height. Please help me how can i get original width and height of image
A:
At least Gecko- (Firefox) and WebKit-based (Safari, Chrome) browsers should implement properties naturalWidth and naturalHeight for image elements:
var image = document.getElementById("imageid");
if (image.naturalHeight === undefined) {
alert("Your browser doesn't support this example!");
} else {
var message = "The original size of the image:";
message += "\n height: " + image.naturalHeight + "px";
message += "\n width: " + image.naturalWidth + "px";
alert(message);
}
kkyy
2010-06-09 07:36:37
@kkyy why not just image.height?
c0mrade
2010-06-09 07:50:59
@c0mrade Because if the image has been scaled the image.width and image.height properties return the scaled size, not the original one. At least in firefox.
kkyy
2010-06-09 08:07:48
@kkyy alright tnx for the info
c0mrade
2010-06-09 08:30:48