Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

read image metadata javascript

function getOrientation(file, callback) {
    var reader = new FileReader();
    reader.onload = function(e) {

        var view = new DataView(e.target.result);
        if (view.getUint16(0, false) != 0xFFD8)
        {
            return callback(-2);
        }
        var length = view.byteLength, offset = 2;
        while (offset < length) 
        {
            if (view.getUint16(offset+2, false) <= 8) return callback(-1);
            var marker = view.getUint16(offset, false);
            offset += 2;
            if (marker == 0xFFE1) 
            {
                if (view.getUint32(offset += 2, false) != 0x45786966) 
                {
                    return callback(-1);
                }

                var little = view.getUint16(offset += 6, false) == 0x4949;
                offset += view.getUint32(offset + 4, little);
                var tags = view.getUint16(offset, little);
                offset += 2;
                for (var i = 0; i < tags; i++)
                {
                    if (view.getUint16(offset + (i * 12), little) == 0x0112)
                    {
                        return callback(view.getUint16(offset + (i * 12) + 8, little));
                    }
                }
            }
            else if ((marker & 0xFF00) != 0xFF00)
            {
                break;
            }
            else
            { 
                offset += view.getUint16(offset, false);
            }
        }
        return callback(-1);
    };
    reader.readAsArrayBuffer(file);
}

// usage:
var input = document.getElementById('input');
input.onchange = function(e) {
    getOrientation(input.files[0], function(orientation) {
        alert('orientation: ' + orientation);
    });
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript foreach break 
Javascript :: cypress json schema vs code 
Javascript :: java convert json string to list of maps 
Javascript :: connected-react-router error could not find router reducer in state tree 
Javascript :: json_decode javascript 
Javascript :: external script in react 
Javascript :: javascript return string 
Javascript :: using underscore javascript number 
Javascript :: javascript number in alphabet 
Javascript :: jquery cdn by google 
Javascript :: js read a ini file 
Javascript :: standalone apk build expo 
Javascript :: javascript Set Intersection Operation 
Javascript :: remove all sign that is not a-b in string js 
Javascript :: how to redirect react router from the app components 
Javascript :: react list 
Javascript :: async function 
Javascript :: jquery date 
Javascript :: closures in javascript 
Javascript :: get the value of an input nativscript 
Javascript :: how to assert in javascript 
Javascript :: javascript between 
Javascript :: how to check if something is array javascript 
Javascript :: javascript include property array object 
Javascript :: Convertir Map a Json 
Javascript :: Connect to socket.io node.js command line 
Javascript :: palindrome javascript 
Javascript :: nodejs end process 
Javascript :: see all set variables chrome 
Javascript :: push values to state array class react 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =