0
votes

I'm using exif-js library to extract the orientation from images uploaded to my web app. I need the exif orientation to rotate incorrectly rotated android images.

The problem is that images uploaded from android device always return 0 as their orientation.

I've tried transfering image taken from the same android device to desktop, and uploading it from there, everything works fine in that case and I get the orientation 6.

localforage.getItem('photo').then(function(value) {
                alert('inside forage');
            image = value;
            alert(image); // i get the image object
            url = window.URL.createObjectURL(image);
            alert(url); // url is correct
                let preview = document.getElementById('camera-feed');
                preview.src = url;
                // const tags = ExifReader.load(image);
                console.log( tags );
            EXIF.getData(image, function() {
               myData = this;
                 if (myData.exifdata.Orientation) {
                        orientation = parseInt(EXIF.getTag(this, "Orientation"));
                        alert(orientation); // on desktop 6, on android always 0
                 }
            });
            ....

I'm using chrome browser on android.

2

2 Answers

0
votes

After a lot of changes in my project, I used this library to handle image rotation on the frontend

0
votes

I know you already solved this, but I would still like to recommend exifr library if you need more than orientation. Or if performance is important to you. Exifr is fast and can handle hundreds of photos without crashing the browser or taking a long time :). Plus there's neat simple API and you feed it with pretty much anything - element, URL, Buffer, ArrayBuffer, even base64 url or string and more.

exifr.orientation(file).then(val => {
  console.log('orientation:', val)
})