相机捕获phonegap2.9.0中的方向问题

时间:2013-10-24 09:20:10

标签: javascript cordova camera screen-orientation

在我的基于phonegap的应用程序中,当我以横向捕获图像时,它以纵向模式显示,我添加了代码

correctOrientation:true

但它仍然以纵向模式显示风景图像。这是代码

function capturePhoto()
{
navigator.camera.getPicture(onPhotoURISuccess,fail, {
    quality: 20,
    correctOrientation: true,
    destinationType:Camera.DestinationType.FILE_URI
});
}  

function onPhotoURISuccess(imageURI) 
{
var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);
options.mimeType = "image/jpeg";
if(App.gvars.userpic=='1')
{
document.getElementById('userpicw').src = imageURI;
}
if(App.gvars.userpic=='2')
{
document.getElementById('productpic').src = imageURI;
}
if(App.gvars.userpic=='3')
{
document.getElementById('userpicws').src = imageURI;
}
var largeImage = document.getElementById('smallImage');
largeImage.style.display = 'block';
App.gvars.userpic='0';
var params = new Object();
params.value1 = "Fastabuy";
options.params = params;
options.chunkedMode = false;
}

我应该怎么做。?

1 个答案:

答案 0 :(得分:0)

You can add server side for image rotate 
        $gallery_path.$vImage_name //imagepathwithname;
       /*================= Mobile Camera Angle Rotate ====================*/

            $exif = exif_read_data($gallery_path.$vImage_name, 0, true);

            if($exif['IFD0']['Orientation'] != ""){

                if($exif['IFD0']['Orientation'] == 6)
                    $degrees = 270;
                else if($exif['IFD0']['Orientation'] == 3)
                    $degrees = 180;
                else
                    $degrees = "";

                if($degrees != ""){
                     // This sets the image type to .jpg but can be changed to png or gif
                    header('Content-type: image/jpeg') ;

                     // Create the canvas
                    $source = imagecreatefromjpeg($gallery_path.$vImage_name) ;
                    /* See if it failed */

                     // Rotates the image
                     $rotate = imagerotate($source, $degrees, 0) ;

                     // Outputs a jpg image, you could change this to gif or png if needed
                     imagejpeg($rotate, $gallery_path.$vImage_name);
                }
            }

        /*================= Mobile Camera Angle Rotate ====================*/