Friday, August 22, 2014

Checking Image resolution using Javascript - Asp.net File Uploader

Script

Download jquery.min.2.0.2.js

  <script src="js/jquery.min2.0.2.js" type="text/javascript"></script>
  <script type="text/javascript">
 function setEvent() {
     $(document.getElementById('<%=flpPhoto.ClientID%>')).change(function() {


         // alert(this.files[0]);
         var reader = new FileReader();
         var image = new Image();
         reader.readAsDataURL(this.files[0]);
         reader.onload = function(_file) {
             image.src = _file.target.result;
             image.onload = function() {
                 var w = this.width;
                 var h = this.height;
                 // alert(w + ' ' + h);
                 if (w != 155 && h != 200) {
                     $(document.getElementById('<%=flpPhoto.ClientID%>')).val('');
                     alert('Invalid Student Photo Size. Please upload photo of resolution 155x200 Pixels.');
                   
                 }

             };
         };
     });
   }

function pageLoad() {
setEvent();
}

  </script>


HTML

 <asp:FileUpload ID="flpPhoto" TabIndex="52" runat="server" />

 

 

No comments:

Post a Comment