I need a JQuery function that return height and width of an image picked from a input type file. I found this function on Stackoverflow:
function getImageWidth(elemento){       
    $.fileImmagine = elemento;      
    var fr = new FileReader;
    // file is loaded    
    fr.onload = function() { 
        var img = new Image;    
        img.onload = function() {           
            alert(img.width);                   
        };
        // is the data URL because called with 
        img.src = fr.result; readAsDataURL
    }; 
    // I'm using a <input type="file"> for demonstrating   
    fr.readAsDataURL($($.fileImmagine)[0].files[0]);    
}
I don't understand how I can edit this function, in order to turn alert(img.width) into return img.width. 
How can I "tell" the function to return the width of the image only after the image i loaded?
Thank you in advance
