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
Regex in Javascript to remove links
Viewed 614 times since Sat, Oct 3, 2020
Strip HTML Tags in JavaScript
Viewed 629 times since Sat, Oct 3, 2020
Hidden image after redirect by check filename
Viewed 704 times since Wed, Sep 30, 2020
Get The Current Domain Name With Javascript (Not the path, etc.)
Viewed 675 times since Fri, Oct 2, 2020
XMLHttpRequest.responseURL
Viewed 586 times since Wed, Sep 30, 2020
How to hide image broken Icon using only CSS/HTML?
Viewed 909 times since Wed, Sep 30, 2020