Is it possible to find the intrinsic size of an image in a HTML document from Javascript?
By default images are assumed to have a "1x" pixel density (1 device pixel = 1 CSS pixel) and so the intrinsic size is simply the pixel height and width. The intrinsic image size and resolution can be explicitly specified in the EXIF data.
The intrinsic size of an element is determined by the contents of an element, without any CSS styles that affect it's final size (rendered size).
You can easily find the original or intrinsic width and heigh of an image using the HTML5 image naturalWidth and naturalHeight properties. These properties are supported in all major web browsers such as Chrome, Firefox, Safari, Opera, Internet Explorer 9 and above.
Very old question, but this is where I ended up when I searched.
These days (since IE9) there are naturalHeight
and naturalWidth
properties:
https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/naturalWidth https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/naturalHeight
I think these give me what I want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With