forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-files-options.js
More file actions
76 lines (60 loc) · 1.46 KB
/
get-files-options.js
File metadata and controls
76 lines (60 loc) · 1.46 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const sharp = require('sharp')
const { getPngCompression, getIcoCompression } = require('./get-compression')
function getRgbColor (color) {
let hex = color.replace(/^#/, '')
if (hex.length === 3) {
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]
}
const num = parseInt(hex, 16)
return {
r: num >> 16,
g: num >> 8 & 255,
b: num & 255,
alpha: 1
}
}
module.exports = async function getFilesOptions ({
quality,
padding,
icon,
background,
pngColor,
splashscreenColor,
...opts
}) {
const qualityLevel = parseInt(quality, 10)
const sharpIcon = sharp(icon).withMetadata()
const sharpBackground = background
? sharp(background).withMetadata()
: sharp({
create: {
width: 12,
height: 12,
channels: 4,
background: { r: 0, g: 0, b: 0, alpha: 0 }
}
})
if (opts.skipTrim !== true) {
sharpIcon.trim()
}
const computedPadding = padding
? (
padding.length === 1
? { horiz: padding[0], vert: padding[0] }
: { horiz: padding[0], vert: padding[1] }
)
: { horiz: 0, vert: 0 }
return {
...opts,
icon: sharpIcon,
iconBuffer: await sharpIcon.toBuffer(),
background: sharpBackground,
compression: {
ico: getIcoCompression(qualityLevel),
png: getPngCompression(qualityLevel),
},
padding: computedPadding,
pngColor: getRgbColor(pngColor),
splashscreenColor: getRgbColor(splashscreenColor)
}
}