cordova-plugin-crop
Crop an image in a Cordova app
Install
$ cordova plugin add --save cordova-plugin-crop
Usage
plugins.crop(function success () {
}, function fail () {
}, '/path/to/image', options)
or, if you are running on an environment that supports Promises
(Crosswalk, Android >= KitKat, iOS >= 8)
plugins.crop.promise('/path/to/image', options)
.then(function success (newPath) {
})
.catch(function fail (err) {
})
API
The resulting JPEG quality. default: 100
Ionic / Typescript Example Angular 2 Service
This is an example service that uses ionic-native's built in camera and the cordova-plugin-crop to created a cropped version of the image and return the file path.
import { Injectable } from '@angular/core';
import { Platform } from 'ionic-angular';
import { Camera } from 'ionic-native';
declare var plugins: any;
@Injectable()
export class CameraService {
public options: any = {
allowEdit: true,
sourceType: Camera.PictureSourceType.SAVEDPHOTOALBUM,
mediaType: Camera.MediaType.ALLMEDIA,
destinationType: Camera.DestinationType.FILE_URI
}
constructor(public platform: Platform) {}
getMedia(): Promise<any> {
return new Promise((resolve, reject) => {
Camera.getPicture(this.options).then((fileUri) => {
if (this.platform.is('android') {
fileUri = 'file://' + fileUri;
const options = { quality: 100 };
plugins.crop.promise(fileUri, options).then( (path) => {
console.log('Cropped Image Path!: ' + path);
resolve(path);
}).catch( (error) => {
reject(error);
});
}
}).catch((error) => {
reject(error);
}
});
}
}
Libraries used
License
MIT © Jeduan Cornejo