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);
});
}
Also in JavaScript:
- javascript exeit from loop
- remove whitespace javascript
- add id to element javascript
- modify array js
- convert datetime value to time only in reactjs
- how to deploy react app firebase
- Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?
- dm message collector discordjs
- jquery get base url
- javascript array remove last
- javascript tap and hold
- jquery abort ajax
- code intialization problem javascript
- checking object is empty in JS
- javascript string includes
- get everything after the first character javascript
- random() number in javascript
- ajax call too functions.php
- get text selected option jquery
- body parser express
- reactjs TypeError: b is undefined
- javascript clone object
- difference between ajax and node js
- Create a node in the Node Editor or Hypershade, press the ____ and type into search bar: