-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebptogif.js
45 lines (43 loc) · 1.22 KB
/
webptogif.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
const sharp = require('sharp');
const path = require('path');
const fs = require('fs');
const rootPath = 'D:/115下载/hentaipaw.com/Jam packed line tale';
async function toGif() {
const dirname = path.basename(rootPath);
const rootDir = 'images/' + dirname;
if (!fs.existsSync(rootDir)) {
fs.mkdirSync(rootDir);
}
let files = walk(rootPath);
for (let index = 0; index < files.length; index++) {
const file = files[index];
// sharp.cache(false);
const metadata = await sharp(file).metadata().catch((err) => {
console.log(err);
console.log(file);
});
const extname = path.extname(file);
const filename = path.basename(file, extname);
if(metadata.format=='webp') {
await sharp(file, { animated: true })
.toFile(rootDir + '/' + filename + '.gif');
}
}
}
toGif()
function walk(dir) {
var results = [];
var list = fs.readdirSync(dir);
list.forEach(function(file) {
file = dir + '/' + file;
var stat = fs.statSync(file);
if (stat && stat.isDirectory()) {
/* Recurse into a subdirectory */
results = results.concat(walk(file));
} else {
/* Is a file */
results.push(file);
}
});
return results;
}