mirror of
https://github.com/voltbonn/profile-picture-generator.git
synced 2024-12-22 15:55:08 +00:00
modified the copied function, to fit the style guide
This commit is contained in:
parent
14757887e0
commit
f70c295da3
1 changed files with 28 additions and 21 deletions
49
src/App.js
49
src/App.js
|
@ -10,41 +10,48 @@ const frameSize = 1080
|
||||||
|
|
||||||
function getOrientation(file, callback) {
|
function getOrientation(file, callback) {
|
||||||
// Source: http://stackoverflow.com/a/32490603
|
// Source: http://stackoverflow.com/a/32490603
|
||||||
var reader = new FileReader();
|
// (With some modifications: I just made the code fit the style-guide.)
|
||||||
|
const reader = new FileReader()
|
||||||
|
|
||||||
reader.onload = function (event) {
|
reader.onload = function (event) {
|
||||||
var view = new DataView(event.target.result);
|
const view = new DataView(event.target.result)
|
||||||
|
|
||||||
if (view.getUint16(0, false) !== 0xFFD8) return callback(-2);
|
if (view.getUint16(0, false) !== 0xFFD8) {
|
||||||
|
return callback(-2)
|
||||||
|
}
|
||||||
|
|
||||||
var length = view.byteLength,
|
const length = view.byteLength
|
||||||
offset = 2;
|
let offset = 2
|
||||||
|
|
||||||
while (offset < length) {
|
while (offset < length) {
|
||||||
var marker = view.getUint16(offset, false);
|
const marker = view.getUint16(offset, false)
|
||||||
offset += 2;
|
offset += 2
|
||||||
|
|
||||||
if (marker === 0xFFE1) {
|
if (marker === 0xFFE1) {
|
||||||
if (view.getUint32(offset += 2, false) !== 0x45786966) {
|
if (view.getUint32(offset += 2, false) !== 0x45786966) {
|
||||||
return callback(-1);
|
return callback(-1)
|
||||||
}
|
}
|
||||||
var little = view.getUint16(offset += 6, false) === 0x4949;
|
const little = view.getUint16(offset += 6, false) === 0x4949
|
||||||
offset += view.getUint32(offset + 4, little);
|
offset += view.getUint32(offset + 4, little)
|
||||||
var tags = view.getUint16(offset, little);
|
const tags = view.getUint16(offset, little)
|
||||||
offset += 2;
|
offset += 2
|
||||||
|
|
||||||
for (var i = 0; i < tags; i++)
|
for (var i = 0; i < tags; i++) {
|
||||||
if (view.getUint16(offset + (i * 12), little) === 0x0112)
|
if (view.getUint16(offset + (i * 12), little) === 0x0112) {
|
||||||
return callback(view.getUint16(offset + (i * 12) + 8, little));
|
return callback(view.getUint16(offset + (i * 12) + 8, little))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if ((marker & 0xFF00) !== 0xFF00) {
|
||||||
|
break
|
||||||
|
} else {
|
||||||
|
offset += view.getUint16(offset, false)
|
||||||
}
|
}
|
||||||
else if ((marker & 0xFF00) !== 0xFF00) break;
|
|
||||||
else offset += view.getUint16(offset, false);
|
|
||||||
}
|
}
|
||||||
return callback(-1);
|
return callback(-1)
|
||||||
};
|
}
|
||||||
|
|
||||||
reader.readAsArrayBuffer(file.slice(0, 64 * 1024));
|
reader.readAsArrayBuffer(file.slice(0, 64 * 1024))
|
||||||
};
|
}
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const [frameURL, setFrameURL] = useState(null)
|
const [frameURL, setFrameURL] = useState(null)
|
||||||
|
|
Loading…
Reference in a new issue