Exif возвращаемое значение -6 - PullRequest
0 голосов
/ 26 апреля 2019

У меня есть следующий javascript, который я пытаюсь использовать для проверки поворота моих изображений при предварительном просмотре.Некоторые из моих изображений вращаются при предварительном просмотре, поэтому я пытаюсь использовать библиотеку exif для обработки поворота.

В приведенном ниже коде я получаю -6 для console.log ('Exif =', EXIF.getTag (this, "Orientation"));и тогда ни один из моих других консольных.логов не сбрасывает.Я не получаю ошибок в своей консоли, но похоже, что функция просто завершается.Может кто-нибудь помочь.Даже если я изменю одну из моих инструкций 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");
}
...