-
-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathpng.js
More file actions
30 lines (21 loc) · 609 Bytes
/
png.js
File metadata and controls
30 lines (21 loc) · 609 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
'use strict'
var str2arr = require('../common').str2arr
var sliceEq = require('../common').sliceEq
var readUInt32BE = require('../common').readUInt32BE
var SIG_PNG = str2arr('\x89PNG\r\n\x1a\n')
var SIG_IHDR = str2arr('IHDR')
module.exports = function (data) {
if (data.length < 24) return
// check PNG signature
if (!sliceEq(data, 0, SIG_PNG)) return
// check that first chunk is IHDR
if (!sliceEq(data, 12, SIG_IHDR)) return
return {
width: readUInt32BE(data, 16),
height: readUInt32BE(data, 20),
type: 'png',
mime: 'image/png',
wUnits: 'px',
hUnits: 'px'
}
}