-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
48 lines (34 loc) · 995 Bytes
/
index.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
36
37
38
39
40
41
42
43
44
45
46
47
48
'use strict'
var detectType = require('image-type')
var toab = require('to-array-buffer')
module.exports = decode
function decode (data, o) {
data = toab(data)
if (!data) return null
if (!o) o = {}
else if (typeof o === 'string') o = {type: o}
var type = o.type
if (!type) {
type = detectType(new Uint8Array(data))
// we do not throw an error since argument can be decoded data already
if (!type) return null
type = type.mime
if (!decode[type]) throw Error('Type `' + type + '` does not seem to be supported')
}
return decode[type](data, o)
}
decode['png'] =
decode['image/png'] = require('./png')
decode['gif'] =
decode['image/gif'] = require('./gif'),
decode['image/jpeg'] =
decode['image/jpg'] =
decode['jpg'] =
decode['jpeg'] = require('./jpg')
decode['bmp'] =
decode['image/bmp'] =
decode['image/bitmap'] = require('./bmp')
decode['tiff'] =
decode['image/tiff'] = require('./tiff')
decode['webp'] =
decode['image/webp'] = require('./webp')