解决IOS上传竖向照片会旋转90度的问题
阅读原文时间:2023年07月09日阅读:1
// 解决IOS上传竖向照片会旋转90度的问题
  rotate() {
    const that = this;
    that.imgOrientation = 1;
    let Orientation = null;
    const _filelist = $('#showImg')[0].files[0];
    $('.weui-uploader__file').removeClass('rotate-90');
    $('.weui-uploader__file').removeClass('rotate-180');
    $('.weui-uploader__file').removeClass('rotate-90-back');
    // 获取图片Orientation参数
    EXIF.getData(_filelist, function () {
      Orientation = EXIF.getTag(this, 'Orientation');
      that.imgOrientation = Orientation;

      if (Orientation) {
        switch (Orientation) {
          case 6:     // 正常竖拍
            $('.weui-uploader__file').addClass('rotate-90');
            break;
          case 3:     // 横线拍-180
            $('.weui-uploader__file').addClass('rotate-180');
            break;
          case 8:     // 竖向拍-180
            $('.weui-uploader__file').addClass('rotate-90-back');
            break;
          default:
            $('.weui-uploader__file').removeClass('rotate-90');
            $('.weui-uploader__file').removeClass('rotate-180');
            $('.weui-uploader__file').removeClass('rotate-90-back');
        }
      }
    });
  }