1var img = new Image();
2img.onload = function() {
3 alert(this.width + 'x' + this.height);
4}
5img.src = 'http://www.google.com/intl/en_ALL/images/logo.gif';
1<!DOCTYPE HTML>
2<html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5 <title>Get image width using File API</title>
6 </head>
7
8 <body>
9 <input type='file' onchange="readURL(this);" />
10
11 <script>
12 function readURL(input) {
13 if (input.files && input.files[0]) {
14 var reader = new FileReader();
15 reader.onload = function (e) {
16 var img = new Image;
17 img.onload = function() {
18 console.log("The width of the image is " + img.width + "px.");
19 };
20 img.src = reader.result;
21 };
22 reader.readAsDataURL(input.files[0]);
23 }
24 }
25 </script>
26 </body>
27</html>
1var img = document.getElementById("myImageID");
2var imgWidth = img.clientWidth;
3var imgHeight = img.clientHeight;