I'm using the Dropzonejs plugin. I want to check the image dimension (width and height) and also the file size when a file is uploaded. I managed to check the dimension and file size but when I combined both of them, it didn't work well.
var maxImageWidth = 2500,
maxImageHeight = 2500;
Dropzone.options.formUserEdit = {
maxFilesize: 2,
acceptedFiles: 'image/*',
success : function(file, Response){
var obj = JSON.parse(Response);
$('#form-user-edit').append('<input type="hidden" name="userprofile" data-ori="'+file.name+'" value="'+obj.filename+'" />');
$('.error-msg').remove();
},
init: function() {
this.on("thumbnail", function(file) {
if (file.width > maxImageWidth || file.height > maxImageHeight) {
file.rejectDimensions();
else {
file.acceptDimensions();
}
})
},
accept: function(file, done) {
file.rejectDimensions = function() {
done("Please make sure the image width and height are not larger than 2500px.");
};
file.acceptDimensions = done;
}
}
if:
upload big dimension image: it accepts the function
upload small dimension image but more than 2MB: it will return
file.acceptDimensions is not a function
or will not go to success