Reputation: 81
I am actually implementing a function to allow user to upload the photos from phone. Is there any image compress plugin / library to recommended? Notes: it is image compression, not image resizing.
Thanks a lot
Upvotes: 1
Views: 2446
Reputation: 1403
Try following CameraOptions with ionic camera plugin.
const options: CameraOptions = {
quality: 20,
targetWidth: 600,
targetHeight: 600,
destinationType: this.camera.DestinationType.DATA_URL,
encodingType: this.camera.EncodingType.PNG,
mediaType: this.camera.MediaType.PICTURE,
sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
allowEdit: true //may not work with some deices
}
It is targetHeight and targetWidth doing the magic. :)
Answer referred from : Ionic image compress
Upvotes: 1
Reputation: 336
Use the Ionic Native Camera function
There is a quality option ranging from 0-100. It will return a compressed image
const options: CameraOptions = {
quality: 50, // Try changing this
destinationType: this.camera.DestinationType.DATA_URL,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE
}
this.camera.getPicture(options).then((imageData) => {
let base64Image = 'data:image/jpeg;base64,' + imageData;
}, (err) => {
// Handle error
});
Upvotes: 2