-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert_heic.js
More file actions
54 lines (44 loc) · 1.51 KB
/
Copy pathconvert_heic.js
File metadata and controls
54 lines (44 loc) · 1.51 KB
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
46
47
48
49
50
51
52
53
54
const fs = require('fs');
const path = require('path');
const heicConvert = require('heic-convert');
const jpeg = require('jpeg-js');
const folders = [
'new_content/Comunion/Comunión',
'new_content/Sacramentos/Sacramentos'
];
async function convertFolder(folderPath) {
if (!fs.existsSync(folderPath)) {
console.log(`Folder not found: ${folderPath}`);
return;
}
const files = fs.readdirSync(folderPath);
for (const file of files) {
if (path.extname(file).toLowerCase() === '.heic') {
const inputPath = path.join(folderPath, file);
const outputPath = path.join(folderPath, path.basename(file, path.extname(file)) + '.jpg');
if (fs.existsSync(outputPath)) {
console.log(`Skipping ${file}, already converted.`);
continue;
}
console.log(`Converting ${file}...`);
try {
const inputBuffer = fs.readFileSync(inputPath);
const outputBuffer = await heicConvert({
buffer: inputBuffer,
format: 'JPEG',
quality: 0.8
});
fs.writeFileSync(outputPath, outputBuffer);
console.log(`Converted to ${outputPath}`);
} catch (error) {
console.error(`Error converting ${file}:`, error.message);
}
}
}
}
async function main() {
for (const folder of folders) {
await convertFolder(folder);
}
}
main();