This article recommends an example of how to use js to obtain the original size of an image, which was extracted from my project. Here I will give it to you and take it away if necessary. 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
The Code is as follows:
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
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.