Skip to content

Instantly share code, notes, and snippets.

@daliborgogic
Created July 10, 2014 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daliborgogic/c1cce5e0e1b0da029657 to your computer and use it in GitHub Desktop.
Save daliborgogic/c1cce5e0e1b0da029657 to your computer and use it in GitHub Desktop.
checking image size before upload
var x = document.getElementById('APP_LOGO'); // get the file input element in your form
var f = x.files.item(0); // get only the first file from the list of files
var filesize = f.size;
alert("the size of the image is : "+filesize+" bytes");
var i = new Image();
var reader = new FileReader();
reader.readAsDataURL(f);
i.src=reader.result;
var imageWidth = i.width;
var imageHeight = i.height;
alert("the width of the image is : "+imageWidth);
alert("the height of the image is : "+imageHeight);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment