Ion cropping image when selecting image from gallery

I used cordova plugin camerain ionic v1 and angular v1. The plugin itself provides the ability to crop images when we take an image from the camera .. but there is no option in choosing an image from the photo library.

              $scope.choosePhoto = function () {
                    var options = {
                    quality: 75,
                    destinationType: Camera.DestinationType.DATA_URL,
                    sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
                    allowEdit: true,
                    encodingType: Camera.EncodingType.JPEG,
                    targetWidth: 200,
                    targetHeight: 200,
                    popoverOptions: CameraPopoverOptions,
                    saveToPhotoAlbum: true
                };

             $cordovaCamera.getPicture(options).then(function (imageData) {
                        $scope.imgURI = "data:image/jpeg;base64," + imageData;
                        window.localStorage.setItem('image',($scope.imgURI));
                    }, function (err) {
                        // An error occured. Show a message to the user
                    });
                }

Is there any solution for cropping the image during gallery image selection. for my project i also use cordova plugin cropfor this. there is an option, for example,

plugins.crop.promise('/path/to/image', options)
.then(function success (newPath) {

})
.catch(function fail (err) {

})

but its not working, and this is only for android, I think ..

who knows about this, please help?

+4
source share
3 answers

iOS, targetWidth, targetHeight. :

targetWidth: 2000, targetHeight: 2000

iOS Android.

0

$cordovaCamera

 navigator.camera.getPicture(gotPhoto, onError, {
                            quality: 90,
                            destinationType: navigator.camera.DestinationType.FILE_URI,
                            sourceType: navigator.camera.PictureSourceType.CAMERA,
                            allowEdit: true, // here it allow to edit pic.
                            encodingType: Camera.EncodingType.JPEG,
                            mediaType: Camera.MediaType.PICTURE,
                            targetWidth: 200, //what widht you want after capaturing
                            targetHeight: 200
                        });

... , .

 navigator.camera.getPicture(gotPhoto, 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
                        });

.

0
 navigator.camera.getPicture(onSuccess, onFail, {
      quality: 50,
      destinationType: Camera.DestinationType.FILE_URI
  });

  function onSuccess(imageData) {
       console.log(imageData);

       /*Crop Image Plugin Code*/
       plugins.crop(function success (data) {
          console.log(data);
          var image = document.getElementById('myImage');
          image.src = data;
       }, 
       function fail () {

       }, imageData, {quality:100});
  }

 function onFail(message) {
    alert('Failed because: ' + message);
 }
0
source

Source: https://habr.com/ru/post/1678340/


All Articles