Get selected image size by javascript

11/01/2018 12:32
 var test = {
 getSelectedPictureSize: function (fileObj) {
        var _deferred = $.Deferred();
 
        var imageSize = { width: 0, height: 0 };
       
        var reader = new FileReader();
       
        reader.readAsDataURL(fileObj);
        reader.onload = function (e) {
       
            var image = new Image();
            //Set the Base64 string return from FileReader as source.
            image.src = e.target.result;
            image.onload = function () {
       
                imageSize = { width: this.width, height: this.height };
                _deferred.resolve(imageSize);
            }
        };
        return _deferred;
    },
}
 
function call
 
//get selected file from input <input type="file" onchange="test.someFunction();" id="sitSelectedFile"  runat="server"/>
 var fileSrc = $('#ctl00_PlaceHolderMain_sitSelectedFile').prop('files')[0];
 test.getSelectedPictureSize(fileSrc).then(function (imageSize) {
console.log(imageSize);
//do your stuff
   
   
});