-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhello.js
More file actions
27 lines (18 loc) · 693 Bytes
/
hello.js
File metadata and controls
27 lines (18 loc) · 693 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
const sharp = require('sharp');
const fs = require('fs');
const inputPath = "images/orig/";
const outputPath = "images/thumbnails/";
const files = fs.readdirSync(inputPath);
for (let i = 0; i < files.length; i++) {
const parts = files[i].split(".");
const extension = parts[parts.length - 1];
const filename = parts.slice(0, parts.length - 1).join(".");
const fullInputName = inputPath + filename + "." + extension;
const fullOutputName = outputPath + filename + "-min." + extension;
sharp(fullInputName)
.resize(600)
.toFile(fullOutputName, (err, info) => {
if (err) console.log(err);
else console.log("converted " + fullInputName + " successfully");
});
}