Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set camera width and height phonegap camera

I am currently in the process of creating a mobile app that uses the Phonegap (Cordova) camera plugin. It correctly captures the image and displays it where I want to, but I can't seem to set the targetWidth and targetHeight options, as described.

targetWidth: Width in pixels to scale image. Must be used with targetHeight. Aspect ratio remains constant. (Number)

targetHeight: Height in pixels to scale image. Must be used with targetWidth. Aspect ratio remains constant. (Number)

As I understand, this will change the image-width and height on output. They, however, don't seem to be working.

A suggestion that I found while researching for a solution, said to use the optional parameter allowEdit. In this I could get the user to select a pre-set squared image. This however, doesn't seem to work either.

See my code below for reference.

camera: function() {
    //Fire up the camera!
    navigator.camera.getPicture(onSuccess, onFail, {
        destinationType: Camera.DestinationType.DATA_URL,
        allowEdit: true,
        targetWidth: 512,
        targetHeight: 512
    });
},

Neither of the attemps succeeded in what I wanted; a fixed width and height for the image captured.

How can I set the image width and height on this image?

like image 770
Matthijs Avatar asked Nov 24 '14 12:11

Matthijs


2 Answers

Try this one my friend. remove allowEdit : true

camera: function() {
        navigator.camera.getPicture(onSuccess, onFail, {
            quality: 50,
            targetWidth: 512,
            targetHeight: 512,
            destinationType: navigator.camera.DestinationType. DATA_URL,
            saveToPhotoAlbum: true,
            correctOrientation: true
        });
    }
like image 172
Nurdin Avatar answered Nov 05 '22 04:11

Nurdin


How about changing your mind to resizing image after it has been captured?

Useful article for resizing image with HTML5 Canvas

like image 28
Jack He Avatar answered Nov 05 '22 05:11

Jack He