-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsharp.js
74 lines (67 loc) · 1.98 KB
/
sharp.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
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
const sharp = require('sharp');
const fs = require('fs');
const path = require('path');
const target = path.resolve(__dirname, 'src/public/images');
const destination = path.resolve(__dirname, 'dist/images');
if (!fs.existsSync(destination)) {
fs.mkdirSync(destination);
}
fs.readdirSync(target).forEach((image) => {
if (image.includes('hero')) {
// convert hero image lebar 1200px
sharp(`${target}/${image}`)
.resize(1200)
.toFile(
path.resolve(
__dirname,
`${destination}/${image.split('.').slice(0, -1).join('.')}-1200.jpg`,
),
);
// convert hero image lebar 1000px
sharp(`${target}/${image}`)
.resize(1000)
.toFile(
path.resolve(
__dirname,
`${destination}/${image.split('.').slice(0, -1).join('.')}-1000.jpg`,
),
);
// convert hero image lebar 600px
sharp(`${target}/${image}`)
.resize(600)
.toFile(
path.resolve(
__dirname,
`${destination}/${image.split('.').slice(0, -1).join('.')}-600.jpg`,
),
);
} else {
// convert loading image lebar 400px
sharp(`${target}/${image}`)
.resize(400)
.toFile(
path.resolve(
__dirname,
`${destination}/${image.split('.').slice(0, -1).join('.')}-400.jpg`,
),
);
// convert loading image lebar 300px
sharp(`${target}/${image}`)
.resize(300)
.toFile(
path.resolve(
__dirname,
`${destination}/${image.split('.').slice(0, -1).join('.')}-300.jpg`,
),
);
// convert loading image lebar 200px
sharp(`${target}/${image}`)
.resize(200)
.toFile(
path.resolve(
__dirname,
`${destination}/${image.split('.').slice(0, -1).join('.')}-200.jpg`,
),
);
}
});