0

I am uploading image and validating that if uploaded image is greater than 500x500 then generate an error. I am using following code to know the dimension.

rules: {
            profile_pic:{accept: "png|jpe?g",imagedim:true}
}

$.validator.addMethod('imagedim', function(value, element, param) { 
  var _URL = window.URL;
        var  img;
        if ((element = this.files[0])) {
            img = new Image();
            img.onload = function () {
                console.log("Width:" + this.width + "   Height: " + this.height);//this will give you image width and height and you can easily validate here....

                return this.width >= param
            };
            img.src = _URL.createObjectURL(element);
        }
});

But this its not returning me uploaded image height width.Every time its submitting form event if I added return false; Please help

Sparky
  • 98,165
  • 25
  • 199
  • 285
John
  • 1,035
  • 2
  • 9
  • 15
  • For one thing, you're incorrectly using the `accept` method in place of [the `extension` method](http://jqueryvalidation.org/extension-method/). The former is for MIME type and the latter is for file extension. – Sparky Mar 10 '16 at 15:07

1 Answers1

-1

Your question is a possible duplicate of this:

Determine original size of image cross browser?

Please check it.

Community
  • 1
  • 1
Ray A
  • 1,283
  • 2
  • 10
  • 22