1

I'm doing a phonegap app and I take a picture with this method:

// A button will call this function
//
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,
        targetWidth: 100
    });
}

But I want to know if there is a way in phonegap to know the weight of the photo that's taken.

jordanhill123
  • 4,142
  • 2
  • 31
  • 40
cristina
  • 21
  • 7

1 Answers1

0

I have looked into this and it seems that the PhoneGap Camera plugin cannot help you with finding out the weight of the produced image.

To explain what happens when you have have taken picture you could do this in your success function:

function onPhotoDataSuccess(imageData) {
    var image = document.getElementById('myImage');
    image.src = "data:image/jpeg;base64," + imageData;
}

You end up with a JavaScript Image object. You can read more here Determining image file size + dimensions via Javascript? about determining image file size in JavaScript, there does not seem to be an easy straightforward solution unfortunately.

Community
  • 1
  • 1
HischT
  • 933
  • 1
  • 9
  • 26
  • Yes that-s what I do with the picture. But at the same time I send it through ajax to a server and I need to know the weight of the image. I'm trying to get the base64 picture from the server to work with it in php. But I can't decode the photo yet. Once I get the photo from php it will be easier to know the weight. – cristina Oct 02 '14 at 06:46
  • So you are asking for size computing in PHP? Have you tried strlen(base64_decode($encoded_data)); ? – HischT Oct 02 '14 at 10:47
  • no I wanted to know the size of the photo before sending it to the server. – cristina Oct 02 '14 at 15:19