forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-square-icon.js
More file actions
49 lines (42 loc) · 890 Bytes
/
get-square-icon.js
File metadata and controls
49 lines (42 loc) · 890 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const { warn } = require('../utils/logger')
module.exports = function getSquareIcon ({
file,
icon,
size,
padding: { horiz, vert },
background = { r: 255, g: 255, b: 255, alpha: 0 }
}) {
const img = icon.clone()
let width = size - 2 * horiz
let height = size - 2 * vert
let corrections = []
if (width <= 0) {
width = size
horiz = 0
corrections.push('width')
}
if (height <= 0) {
height = size
vert = 0
corrections.push('height')
}
if (corrections.length > 0) {
warn(`Correction on padding for ${file.relativeName} due to padding exceeding file's dimension of ${size}x${size}px`)
}
img.resize({
width,
height,
fit: 'contain',
background
})
if (horiz > 0 || vert > 0) {
img.extend({
top: vert,
bottom: vert,
left: horiz,
right: horiz,
background
})
}
return img
}