forked from SidOfc/leather
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpng.js
More file actions
35 lines (27 loc) · 787 Bytes
/
png.js
File metadata and controls
35 lines (27 loc) · 787 Bytes
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 attributes(input) {
const stream = lazystream(input);
const isMNG = stream.take(4).includes('MNG');
const isFried = stream.skip(8).take(4).includes('CgBI');
if (isFried) stream.skip(16);
const result = {
width: stream.takeUInt32BE(),
height: stream.takeUInt32BE(),
size: stream.size(),
mime: isMNG
? 'video/x-mng'
: isAPNG(stream)
? 'image/apng'
: 'image/png',
};
stream.close();
return result;
}
function isAPNG(stream) {
const position = stream.position();
const result = [256, 512, 1024].some((size) =>
stream.take(size).includes('acTL')
);
stream.goto(position);
return result;
}