首页 > 解决方案 > Exif 返回值为 -6

问题描述

我有以下 javascript,我试图用它来检查我的图像在预览时的旋转。我的一些图像在预览时被旋转,所以我试图使用 exif 库来处理旋转。

在下面的代码中,我得到 -6 的 console.log('Exif=', EXIF.getTag(this, "Orientation")); 然后我的其他 console.logs 都没有转储。我的控制台中没有任何错误,但看起来该功能刚刚退出。有人可以帮忙吗。即使我将其中一个 case 语句更改为 -6,该 case 语句仍然不会被调用。有任何想法吗?

// UPLOAD IMAGE PREVIEW
function readURL(input) {
console.log("aaaa");
    if (input.files && input.files[0]) {
        var reader = new FileReader();
 console.log("here544");
        reader.onload = function (e) {
            var img = $('#_nc_image_default')
            fixExifOrientation(img)
            console.log("here5");
            img.attr('src', e.target.result);


        };

        reader.readAsDataURL(input.files[0]);
    }
}

function fixExifOrientation($img) {
    $img.on('load', function() {
        EXIF.getData($img[0], function() {
            console.log('Exif=', EXIF.getTag(this, "Orientation"));
            switch(parseInt(EXIF.getTag(this, "Orientation"))) {
                case 2:
                    $img.addClass('flip'); 
                    break;
                case 3:
                    $img.addClass('rotate-180'); 
                    break;
                case 4:
                    $img.addClass('flip-and-rotate-180'); 
                    break;
                case 5:
                    $img.addClass('flip-and-rotate-270'); 
                    break;
                case 6:
                    $img.addClass('rotate-90'); 
                    break;
                case 7:
                    $img.addClass('flip-and-rotate-90'); 
                    break;
                case 8:
                    $img.addClass('rotate-270'); 
                    break;
                   default:
                    console.log("here");
                    break;

            }
            console.log("here2");
            $img.addClass('flip-and-rotate-180');
        });
        console.log("here3");
    });
    console.log("here4");
}

标签: javascriptexifexif-js

解决方案


推荐阅读