-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
28 lines (25 loc) · 941 Bytes
/
index.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
const fs = require("fs");
const path = require("path");
const cr2Raw = require("cr2-raw");
const inputFolder = "./Images/ToConvert";
const outputFolder = "./Images/Converted";
// Read the input folder and convert all CR2 files to PNG
fs.readdir(inputFolder, (err, files) => {
if (err) {
console.error(`Error reading the input folder: ${err.message}`);
} else {
const cr2Files = files.filter(
(file) => path.extname(file).toLowerCase() === ".cr2"
);
cr2Files.forEach((cr2File) => {
const cr2FilePath = path.join(inputFolder, cr2File);
console.log("Processing:", cr2FilePath);
convertCR2toPNG(cr2FilePath);
});
}
});
const convertCR2toPNG = (cr2FilePath) => {
const outputFileName = path.basename(cr2FilePath, path.extname(cr2FilePath)) + ".png";
var raw = cr2Raw(cr2FilePath);
fs.writeFileSync(`${outputFolder}/${outputFileName}`, raw.previewImage());
};