-1

I need to check dimensions of image before upload. I have created a function in javascript for validation as follows

$('#destSubmit').click(function() { 
    var img = document.getElementById('destImage'); 
    var width = img.naturalWidth ; 
    var height = img.naturalHeight ; 
    console.log('width : ' + width + '|| Height : ' + height);
    if(height != 100 || width != 100){
        alert(error);
    }
}

But it shows width and height as undefined;

I know this is a repeated question, but I cannot find a solution after a long research. Tried the solution listed here How to get image size (height & width) using JavaScript?, but no use.

sjahan
  • 5,720
  • 3
  • 19
  • 42
geeth
  • 704
  • 2
  • 14
  • 42

1 Answers1

5

You can use jQuery , like below

$('#destSubmit').click(function() {        
    var width = $("#destImage").width(); 
    var height = $("#destImage").height(); 
    console.log('width : ' + width + '|| Height : ' + height);
    if(height != 100 || width != 100){
        alert(error);
    }
}
Praveen Kumar
  • 1,966
  • 1
  • 9
  • 16