I am working on MVC 5 project, there I am trying to crop and validate the image width and height.
Here jQuery code, reader.readAsDataURL(this.files[0])
is occurring error 'Cannot read property '0' of undefined' .
var imageCropWidth = 0;
var imageCropHeight = 0;
var cropPointX = 0;
var cropPointY = 0;
var _URL = window.URL || window.webkitURL;
$('#files').change(function () {
debugger
var file, img;
if ((file = this.files[0])) {
img = new Image();
img.onload = function () {
if (this.width <= 200 && this.height <= 200) {
var reader = new FileReader();
reader.onload = function (e) {
// get loaded data and render thumbnail.
document.getElementById("image").src = e.target.result;
var jcrop_api = $('#image').Jcrop({
setSelect: [500, 500, 10, 10],
allowMove: true,
allowResize: false,
onChange: setCoordsAndImgSize,
boxWidth: 500,
boxHeight: 500
//onSelect: updatePreview
});
//jcrop_api.setOption({ allowMove: false });
//jcrop_api.setOption({ allowResize: false })
};
// read the image file as a data URL.
reader.readAsDataURL(this.files[0]);
loadPopup();
}
else {
//$("#txtfileTitle").attr("placeholder", "Upload Image");
var message = "Image should be maximum 200x200 pixel size.";
errormesssage(message);
return false;
}
};
img.src = _URL.createObjectURL(file);
}
});
How can I solve this error ?
And, Is this good approach to validate the image width and height before or after cropping?