How to resize base64 encoded image in Ionic framework.
I want to resize image on client side before uploading to server.
What is the best strategy in this case ?
How to resize base64 encoded image in Ionic framework.
I want to resize image on client side before uploading to server.
What is the best strategy in this case ?
I solved this with using ng2-img-max library:
uploadDesktopFile() {
let file = this.documentEl.nativeElement.files[0];
const maxHeight = 800;
const maxWidth = 600;
let self = this;
this.ng2ImgMax.resizeImage(file, maxHeight, maxWidth).subscribe(
result => {
let reader = new FileReader();
reader.readAsDataURL(result);
reader.onloadend = function () {
self.imageURI = reader.result; // we've got resized base64 sequence at this stage
//self.uploadFile();
}
reader.onerror = function (error) {
console.error('Error: ', error);
};
},
error => {
console.error('Error: ', error);
}
);
}