0

I have the following javascript that I am trying to use to check the rotation of my images on preview. Some of my images are being rotated on preview so I am trying to use the exif library to handle the rotation.

In the code below, I am getting -6 for the console.log('Exif=', EXIF.getTag(this, "Orientation")); and then none of my other console.logs are dumping. I get no errors in my console but it looks like the function is just exiting. Can someone help. Even if I change one of my case statements to -6, that case statement still doesn't get called. Any ideas?

// 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");
}
BEP
  • 39
  • 6

0 Answers0