NHTorres
NHTorres

Reputation: 1538

Uncompressed size of images taken with the camera phonegap

I'm up to my server images, images taken from the camera of my device but the truth weigh much to be exact 5.4 MB and in very good quality. I wondered if there was some kind of parameter to be declared for the quality or at least the weight of the file is lower.

Camera.getPicture().then(function(imageURI) {
  $scope.imagen = imageURI;
  $scope.lastPhoto = imageURI;
  $scope.mostrar_form = true;
  $scope.mostrar_boton_view = false;
  google.maps.event.addDomListener(window, 'load', initialize);  
  initialize();
  document.getElementById('buton_refresh').click(); 
  $( "#buton_refresh" ).trigger( "click" );
}, function() {
  $scope.mostrar_boton_view = true;
  $ionicHistory.goBack();
}, {
  quality: 50,
  destinationType: Camera.DestinationType.FILE_URI,
  allowEdit: true,
  encodingType: Camera.EncodingType.JPEG,
  popoverOptions: CameraPopoverOptions,
  saveToPhotoAlbum: true,
  correctOrientation: true
})

Function upload image:

$scope.publicarView = function(){
var server = URL_BASE+'addView/'+sessionService.get("user_id")+"/"+$scope.data.content+"/null/"+$scope.latitud+"/"+$scope.longitud+"/"+1;

var trustAllHosts = true;

var ftOptions = new FileUploadOptions();
ftOptions.fileKey = 'file';
ftOptions.fileName = $scope.imagen.substr($scope.imagen.lastIndexOf('/') + 1);
ftOptions.mimeType = 'image/jpeg';
ftOptions.httpMethod = 'POST';

console.log(ftOptions);

$cordovaFileTransfer.upload(encodeURI(server), $scope.imagen, ftOptions, trustAllHosts)
.then(function(result) {
  console.log(result)
}, function(err) {
  // Error
  console.log(err);
}, function (progress) {

  });
}

Upvotes: 0

Views: 963

Answers (1)

aorfevre
aorfevre

Reputation: 5064

Cordova Camera plugin can be used with the following parameters :

var options = {
    quality: 50,
    destinationType: Camera.DestinationType.NATIVE_URL,
    sourceType: Camera.PictureSourceType.CAMERA,
    allowEdit: false,
    encodingType: Camera.EncodingType.JPEG,
    targetWidth: 700,
    targetHeight: 700,
    popoverOptions: CameraPopoverOptions,
    saveToPhotoAlbum: false,
    correctOrientation: true
};

The following parameters have impacts on the size:

quality: 50,
targetWidth: 700,
targetHeight: 700,

See official doc here : https://github.com/apache/cordova-plugin-camera

For exemple, my code to take a picture looks something like ;

var options = {
        quality: 50,
        destinationType: Camera.DestinationType.NATIVE_URL,
        sourceType: Camera.PictureSourceType.CAMERA,
        allowEdit: false,
        encodingType: Camera.EncodingType.JPEG,
        targetWidth: 700,
        targetHeight: 700,
        popoverOptions: CameraPopoverOptions,
        saveToPhotoAlbum: false,
        correctOrientation: true
    };

    $cordovaCamera.getPicture(options).then(function(imageData) {

        d.resolve( { "img" : imageData });

    }, function(err) {
        d.reject(err);
    });

Upvotes: 0

Related Questions