【问题标题】:Can't get a orientation from image无法从图像中获取方向
【发布时间】:2020-08-16 01:58:32
【问题描述】:

我正在研究一种解决方案,以解决由某些手机制作的图像由于在 exif 数据中具有方向而出现横向或上下颠倒的问题。到目前为止,我已经获得了方向,但是这个变量没有及时传递回去以进行下一个旋转步骤。

function getOrientation(image){
    let ort = 1;
    EXIF.getData(image, function () {
        ort = EXIF.getTag(this, 'Orientation');
    });
    return ort;
}

来自 ort 的值稍后与画布结合使用以旋转上传的图像。如下图,但是每次改变都会使值变成1或者undefined。

    let orientation = getOrientation(files);
    let data = rotateImage(files, orientation);

将名为 ort 的变量传递回调用 getOrientation() 的函数的最佳方法是什么?

【问题讨论】:

    标签: javascript exif-js


    【解决方案1】:

    在尝试了多种方法后,我能够通过将 orientation 设为全局变量并使用 setTimeout 延迟执行 rotateImage 来修复它。通过这样做,getOrientation 可以完成,rotateImage 可以在超时结束后使用 let 方向。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-20
      • 1970-01-01
      • 2012-06-12
      • 2020-10-22
      • 1970-01-01
      • 2016-08-04
      • 1970-01-01
      • 2017-01-29
      相关资源
      最近更新 更多