0

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

MDP
  • 4,177
  • 21
  • 63
  • 119
  • Possible duplicate of [image.onload function with return](http://stackoverflow.com/questions/7434371/image-onload-function-with-return) – insertusernamehere Jul 05 '16 at 07:48
  • returning height and width of image after uploading - http://codepen.io/nagasai/pen/jAwzaG Hope this works for you – Naga Sai A Jul 05 '16 at 07:49

0 Answers0