Reputation: 1
I am using Cordova camera plugin
. When I take a picture via a camera, it shows crop option. But when I select an image from gallery it does not provide crop option.
Can any one help me in same to have a crop option when I select picture from gallery
var options = {
quality: 100,
allowEdit : 1,
targetWidth: 800,
targetHeight: 800,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: sourceType,
encodingType: 0,
saveToPhotoAlbum: false
};
Upvotes: 0
Views: 844
Reputation: 314
here's the code which I think would be easy to understand
function clickFirstProfilePhoto(){
navigator.camera.getPicture(onPhotoDataSuccess, onFail,
{correctOrientation:true,
targetWidth:1024,
targetHeight: 1024,
destinationType: destinationType.FILE_URI
});
//alowEdit is false by default if you don't mention
}
function onPhotoDataSuccess(imageData) {
plugins.crop.promise(imageData).then(function success (imageFinal) {
// Success.
//alert(imageFinal);
var fileURI = imageFinal.substr(imageFinal.lastIndexOf('?') + 1);
//alert(fileURI);
resolveLocalFileSystemURL(imageFinal, function(entry) {
$("#picPreviewBox").html('<img src="'+entry.toInternalURL()+'" width="100%" />');
//write a code to upload the picture to the server (I am currently stuck here btw)
});
}).catch(function fail (err) {
// fail
$.alert("Seems your phone resources are too low to proceed further");
});
}
function onFail(message) {
navigator.notification.alert('Failed because ' + message);
//$.alert("Sorry! something went wrong. Please restart this app and try again. In case if you still face any problem please report the bug on [email protected]");
}
Upvotes: 0
Reputation: 314
in order to allow the crop option you must type true for allowEdit as it's a Boolean. However as our friend has said above, it's better if you use the plugin cordova-plugin-crop as allowEdit fails on some devices
Upvotes: 1
Reputation: 2224
for cropping the image from gallery in Cordova camera plugin
does not have support. for this you have to combine Cordova camera plugin
with cordova-plugin-crop
try this code instead of your code.
navigator.camera.getPicture(gotPhotoLibrary, onError, {
quality: 50,
destinationType: navigator.camera.DestinationType.FILE_URI,
sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY,
allowEdit: true,
targetWidth: 200, //what widht you want after capaturing
targetHeight: 200
});
return true;
function gotPhotoLibrary(imageUri) {
var options = {
quality: 150,
widthRatio: 1,
heightRatio: 1,
targetWidth: 600,
targetHeight: 600
};
plugins.crop.promise(imageUri, options)
.then(function success(newPath) {
window.resolveLocalFileSystemURI(newPath, function (fileEntry) {
fileEntry.file(function (fileObj) {
// your code here
});
});
});
}
function onError(err) {
alertPopup = $ionicPopup.alert({
title: '',
template: err
});
}
Upvotes: 1