Home » Categories » JavaScript

Check image width and height before upload with Javascript

var _URL = window.URL || window.webkitURL;
$("#file").change(function (e) {
var file, img;
if ((file = this.files[0])) {
img = new Image();
var objectUrl = _URL.createObjectURL(file);
img.onload = function () {
alert(this.width + " " + this.height);
_URL.revokeObjectURL(objectUrl);
};
img.src = objectUrl;
}
});

 

Reference:

https://stackoverflow.com/questions/8903854/check-image-width-and-height-before-upload-with-javascript/8904008

Article Rating (No Votes)
Rate this article
  • Icon PDFExport to PDF
  • Icon MS-WordExport to MS Word
 
Attachments Attachments
There are no attachments for this article.
Comments Comments
There are no comments for this article. Be the first to post a comment.
Related Articles RSS Feed
Hidden image after redirect by check filename
Viewed 515 times since Wed, Sep 30, 2020
Regex in Javascript to remove links
Viewed 441 times since Sat, Oct 3, 2020
How to hide image broken Icon using only CSS/HTML?
Viewed 703 times since Wed, Sep 30, 2020
XMLHttpRequest.responseURL
Viewed 430 times since Wed, Sep 30, 2020
Strip HTML Tags in JavaScript
Viewed 467 times since Sat, Oct 3, 2020
Get The Current Domain Name With Javascript (Not the path, etc.)
Viewed 493 times since Fri, Oct 2, 2020