forked from louisbarclay/nudge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimg.js
38 lines (33 loc) · 993 Bytes
/
img.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
// Utility script to make smaller versions of backgrounds
var sharp = require("sharp");
var fs = require("fs");
var dir = "extension/img/bg";
const bgDir = fs.readdirSync(dir);
console.log(bgDir);
var bgImages = [];
bgDir.forEach(function(item) {
if (item.includes(".jpg")) {
bgImages.push(item);
var originalImage = sharp(fs.readFileSync(`${dir}/${item}`))
.resize(200)
.toBuffer()
.then(data =>
fs.writeFile(`${dir}/small/${item}`, data, "binary", function(err) {})
)
.catch(err => console.log(err));
// var newImage = sharp(fs.readFileSync(`${dir}/${item}`))
// .resize(1920)
// .toBuffer()
// .then(data =>
// fs.writeFile(`${dir}/big/${item}`, data, "binary", function (err) { })
// )
// .catch(err => console.log(err));
}
});
// Output a JS array of all bg files
fs.writeFile(
`extension/js/bgImages.js`,
`var bgImages = ${JSON.stringify(bgImages)};`,
"binary",
function(err) {}
);