-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerateTraceThumb.js
More file actions
36 lines (30 loc) · 966 Bytes
/
Copy pathgenerateTraceThumb.js
File metadata and controls
36 lines (30 loc) · 966 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
const sharp = require('sharp');
const path = require('path');
const fs = require('fs');
const glob = require('glob');
const {promisify} = require('util');
const pGlob = promisify(glob);
const imgsDir = path.join('./src/assets/', '**/*.+(jpg|png)');
pGlob(imgsDir)
.then(files => {
Promise.all(
files.filter(file => !/\.(thumb|primitive|trace)\./.test(file)).map(processFile)
)
});
function processFile(file) {
console.log(`Processing file ${file}`);
const process = (...callers) => Promise.all(callers.map(caller => caller(file)))
return process(generateThumb);
}
const addThumbToName = filePath => {
const parts = filePath.split('.')
return [parts[0], '.thumb.', parts[1]].join('')
};
function generateThumb(file) {
const thumb = addThumbToName(file);
return sharp(file)
.resize(64, 64)
.max()
.toFile(thumb)
.then(() => console.info(`Outputed file ${thumb}`))
}