javascript how to get picture width


How to get picture width ?!

clientWidth and clientHeight are DOM properties that show the current in-browser size of the inner dimensions of a DOM element (excluding margin and border。

var img = document.getElementById('imageid'); 
//or however you get a handle to the IMG
var width = img.clientWidth;
var height = img.clientHeight;
 
============================= 
How to get upload picture width ?!
 
<input type="file" name="photo" id="photoInput" onchange="checkPhoto(this)"/>
 
var _URL = window.URL || window.webkitURL;
$("#photoInput").change(function (e) {
    var file, img;
    if ((file = this.files[0])) {
        img = new Image();
            img.src = _URL.createObjectURL(file); 
        img.onload = function () {
            alert(this.width + " " + this.height);
        };
       
    }
}); 

留言

熱門文章