-
Notifications
You must be signed in to change notification settings - Fork 2
/
jpg.js
35 lines (26 loc) · 809 Bytes
/
jpg.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import {lazystream} from '../util.js';
export function readMediaAttributes(input) {
const stream = lazystream(input);
const result = {
width: 0,
height: 0,
size: stream.size(),
mime: 'image/jpeg',
};
stream.skip(4);
while (stream.more()) {
stream.skip(stream.takeUInt16BE() - 2);
const header = stream.take(2);
const mark = header.readUInt8();
const next = header.readUInt8(1);
if (mark !== 0xff) break;
if (next === 0xc0 || next === 0xc1 || next === 0xc2) {
const dimensions = stream.skip(3).take(4);
result.height = dimensions.readUInt16BE();
result.width = dimensions.readUInt16BE(2);
break;
}
}
stream.close();
return result;
}