Use js to get the original image size and js to get the size
The size of the image displayed in the browser may not be his real height or width. For example, we add a width or height style to the image like below.
In this way, the size displayed in the browser is 25px. So how can we get the real size of the image ?, The following code implements this function
Copy codeThe Code is as follows:
<! DOCTYPE html>
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
</Head>
<Body>
<Script>
// Set the delay to ensure image loading is complete
SetTimeout (function (){
Var
Real_width,
Real_height,
_ Im = document. getElementById ('image '),
Im = document. createElement ('img ');
Im. src = _ im. src,
Real_width = im. width,
Real_height = im. height;
Alert (real_width + '\ n' + real_height );
},500 );
</Script>
</Body>
</Html>
Note: The above code has been tested on IE7 + and chrome, and cannot be tested because IE6 is not installed.
Very easy-to-use code, which is used in most projects.