I am using this lib to resize and compress images before upload
I resize my images like this:
var imgOne = $('#u-fileUpload-1')[0].files[0];
var imgTwo = $('#u-fileUpload-2')[0].files[0];
if (imgOne !== undefined) {
ImageResizer.resizeImage(imgOne, resizeOptions, function(result) {
_this.imgArray.push(result);
});
}
if (imgTwo !== undefined) {
ImageResizer.resizeImage(imgTwo, resizeOptions, function(result) {
_this.imgArray.push(result);
});
}
I resize my images and store them in a array called imgArray
The only problem is that these functions are asynchronous. So my code ends up posting/uploading the form with imgArray
being empty since the resize functions has not finished.
So is there any way to chain these functions or check when they both is done?
Thanks