Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Phonegap Camera API allowEdit, set image always square

Hi I'm using the phonegap Camera API on iOS. I'd like to take picutres in a square 640x640 format. This works fine when I use the sourceType of the camera. But if I use this targetWidth and targetHeight in the sourceType for the phones image library, it will only work if the image fits fully into the defined square. If the image from the library is taken in landscape and the height is smaler than the defined targetHeigt (640), the image won't be square and it will keep its orignal height. I was expecting a black boxing which fills up the empty space so it will be 640. This only hapens when I use the camera and taking a landscape picture and setting correctOrientation:1.

Here my code for camera and photolibrary

Camera:

var options =   {
        quality: 49,
        allowEdit : true,
        targetWidth: 640, 
        targetHeight: 640, 
        correctOrientation: 1, 
        saveToPhotoAlbum: 1,
        //destinationType: Camera.DestinationType.FILE_URI,
        destinationType: navigator.camera.DestinationType.FILE_URI,
        sourceType: 1,      // 0:Photo Library, 1=Camera, 2=Saved Photo Album
        encodingType: 0     // 0=JPG 1=PNG
    }
    navigator.camera.getPicture(onSuccess,onFail,options, {limit:2});

Library:

var options =   {
        quality: 49,
        allowEdit : true,
        targetWidth: 640, 
        targetHeight: 640, 
        correctOrientation: 1,
        //destinationType: Camera.DestinationType.FILE_URI,
        destinationType: navigator.camera.DestinationType.FILE_URI,
        sourceType: 0,      // 0:Photo Library, 1=Camera, 2=Saved Photo Album
        encodingType: 0     // 0=JPG 1=PNG
    }
    navigator.camera.getPicture(onSuccess,onFail,options);
like image 831
user3216026 Avatar asked Jun 06 '14 12:06

user3216026


1 Answers

  • I suggest you use image-cropper-touch
  • I have also get in this bug. I think you will be disappointed just only use cordova-plugin-camera. After get the image, you can add a function CropperImage.
like image 144
Zhongyuan Zhou Avatar answered Oct 23 '22 04:10

Zhongyuan Zhou