Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Script to find intrinsic size of HTML image

Is it possible to find the intrinsic size of an image in a HTML document from Javascript?

like image 534
Leif Arne Storset Avatar asked Feb 24 '16 15:02

Leif Arne Storset


People also ask

How do you measure intrinsic image size?

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.

What is intrinsic size vs rendered size?

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).

How do you find the width and height of an image in HTML?

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.


1 Answers

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.

like image 188
zod Avatar answered Oct 05 '22 23:10

zod