通过PhoneGap(iOS)上传后图像侧向/上下颠倒

Jos*_*ett 6 image file-transfer cordova

不确定是什么原因造成这种情况,但是当我将一些图像上传到我的远程服务器时FileTransfer(),图像有时会出现在侧面或上下颠倒.但是,当我在iPhone上本地查看图像时,它们以正确的方式定位.

例如,当我选择这样的图像上传时:http://sharefa.st/view/WBe2QNSK8r8z

结果如下:http://sharefa.st/view/EWdW1Z4G8r8z

我使用本地路径传输文件,所以我不明白为什么图像会"随机"旋转.

这是我的上传功能:

function uploadPhoto() {

    var options = new FileUploadOptions();
    options.fileKey  = 'file';
    options.fileName = imgURI.substr(imgURI.lastIndexOf('/')+1);
    options.mimeType = 'image/jpeg';

    var params = new Object();

    if(logged_in == true) {

        params.unique_id  = app_unique_id; 
        params.secret_key = user_secret_key;

    }

    options.params = params;

    loadingStart();

    var ft = new FileTransfer();

    ft.upload(imgURI, 'http://' + remote_server + '/API/upload', uploadDetails, fail, options);

}
Run Code Online (Sandbox Code Playgroud)

imgURI 值看起来像这样:

file://localhost/var/mobile/Applications/<snip>/tmp/photo_015.jpg
Run Code Online (Sandbox Code Playgroud)

任何见解都表示赞赏.

Jos*_*ett 16

感谢Humanoidism指出问题实际上是iPhone及其存储图像的方式,我能够找到解决方案.

要以正确的方向上传照片,您必须将correctOrientation设置添加到选项数组中getPicture(),然后将其设置为true.

这是两个例子:

function capturePhoto() {

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

}

function getPhoto(source) {

    navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 30, 
    destinationType: destinationType.FILE_URI,
    sourceType: source,
    correctOrientation: true });

}
Run Code Online (Sandbox Code Playgroud)