- 
      
 - 
        
Save avidmaulanas/8f10d4cf80a2cb16c79348fa9ea981d4 to your computer and use it in GitHub Desktop.  
    Simple Validation and Preview for Image Upload (JavaScript)
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | var _URL = window.URL || window.webkitURL; | |
| $("#article_image").change(function(){ | |
| var file, img, reader; | |
| if ((file = this.files[0])) { | |
| img = new Image(); | |
| img.onload = function(){ | |
| if ( (this.width < 960) || (this.height < 300) ) { | |
| alert("Image must be larger than 960x300 pixels!") | |
| } else { | |
| reader = new FileReader(); | |
| reader.onload = function (e) { | |
| $('#image-preview').attr('src', e.target.result); | |
| } | |
| reader.readAsDataURL(file); | |
| } | |
| } | |
| img.src = _URL.createObjectURL(file); | |
| } | |
| }); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment