-
-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathico.js
More file actions
46 lines (36 loc) · 1.02 KB
/
ico.js
File metadata and controls
46 lines (36 loc) · 1.02 KB
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
36
37
38
39
40
41
42
43
44
45
46
'use strict'
var readUInt16LE = require('../common').readUInt16LE
var HEADER = 0
var TYPE_ICO = 1
var INDEX_SIZE = 16
// Format specification:
// https://en.wikipedia.org/wiki/ICO_(file_format)#Icon_resource_structure
module.exports = function (data) {
var header = readUInt16LE(data, 0)
var type = readUInt16LE(data, 2)
var numImages = readUInt16LE(data, 4)
if (header !== HEADER || type !== TYPE_ICO || !numImages) {
return
}
if (data.length < 6 + numImages * INDEX_SIZE) return
var variants = []
var maxSize = { width: 0, height: 0 }
for (var i = 0; i < numImages; i++) {
var width = data[6 + INDEX_SIZE * i] || 256
var height = data[6 + INDEX_SIZE * i + 1] || 256
var size = { width: width, height: height }
variants.push(size)
if (width > maxSize.width || height > maxSize.height) {
maxSize = size
}
}
return {
width: maxSize.width,
height: maxSize.height,
variants: variants,
type: 'ico',
mime: 'image/x-icon',
wUnits: 'px',
hUnits: 'px'
}
}