-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildImages.js
37 lines (30 loc) · 1.08 KB
/
buildImages.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
const sharp = require('sharp');
const gifsicle = require('gifsicle');
const fs = require('fs');
const { execFile } = require('child_process');
const folder = './static/emojis/large';
const output = './static/emojis';
function build() {
const started = microSeconds();
console.log('Building Images...');
const files = fs.readdirSync(folder);
for(const file of files) {
if(file == 'resized') continue;
if(file.match(/\.gif$/)) {
execFile(gifsicle, ['--resize-fit-width', '48', '-o', `${output}/${file}`, `${folder}/${file}`]);
} else if(file.match(/\.png$/)) {
sharp(`${folder}/${file}`).resize({width: 48}).toFile(`${output}/${file}`).catch(e => {
console.info(`Happened while parsing: ${file}`);
console.error(e);
});
} else {
console.info(`Who tried to something other than a .gif or .png???? Remove ${file}`);
}
}
console.log(`Finished Building Images! Took: ${(microSeconds() - started) / 1000} ms.`);
}
function microSeconds() {
var hrTime = process.hrtime()
return hrTime[0] * 1000000 + hrTime[1] / 1000
}
build();