6

I can only find information in their docs about the Accelerometer for returning device orientation. Is there anyway phonegap can return what way the device was being held when a picture was taken? To use the camera, I do this:

function capturePhoto() {
    // Take picture using device camera and retrieve image as base64-encoded string
    navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
        destinationType: destinationType.DATA_URL });
}

When it returns successful, it does this.

 function onPhotoDataSuccess(imageData) {
        var baseImg = imageData;
        $('#uploadPreUpImgSwapHtml').html('<img src="data:image/jpeg;base64,'+ baseImg +'" style="max-width:100%; width:auto; max-height:300px; height:auto;" / >');
        $('#uploadPreBaseDataSwapHtml').html('<input type="hidden" id="chosenPictureData" value="'+ baseImg +'" />');
        $('#uploadPictureBtnHideHtml').fadeIn();

    }

Is there a callback to the success that returns what way the device was being held while the picture was taken so I can send it to my upload file and rotate the picture correctly?

user1053263
  • 722
  • 2
  • 16
  • 33

1 Answers1

23

To make your life easier you can just call:

navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
    destinationType: destinationType.FILE_URI, 
    correctOrientation: true });

then you'll get a file that is rotated properly.

Simon MacDonald
  • 23,253
  • 5
  • 58
  • 74
  • 2
    Ohh wow!! This worked splendid!! Thank you so much! I didn't see that in the documents and when I googled the answer, and found this http://stackoverflow.com/questions/9902797/phone-gap-camera-orientation they said the only reason that was happening was because I was using base64 and that data doesn't get passed along with base64. – user1053263 Oct 03 '12 at 22:40
  • Thank you very much! This solved my issue on Samsung-Devices where I always got an image in landscape orientation (although the device was in potrait orientation) –  Mar 13 '15 at 14:34
  • Outstanding, going to try this tonight on a project I'm working on, I hope it works!! – Mike May 19 '15 at 17:46
  • Hey, when i use this piece it does't call camera. I'm using "cordova-plugin-media-capture-r0.3.3" plugin. Can you please clarify? – Wanna Coffee Feb 04 '16 at 16:10
  • what about recording video from camera? – Maveňツ Nov 24 '16 at 10:41