-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (34 loc) · 1.44 KB
/
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const path = require('path');
const fs = require('fs');
const convert = require('heic-convert');
const { promisify } = require('util');
async function convertHEICtoPNG() {
try {
const inputFolderDir = path.join(__dirname, 'heic_photos');
fs.readdir(inputFolderDir, (err, files) => {
if (!files || files.length === 0) {
console.log("No files found in the directory.")
return;
}
console.log(`Found ${files.length} files in the directory. Beginning conversion...`)
files.forEach(async file => {
if (!file.endsWith('.HEIC')) {
return;
}
const inputFileDir = path.join(__dirname, 'heic_photos', file);
const outputFileDir = path.join(__dirname, 'converted_photos', file.replace('.HEIC', '.png'));
const inputBuffer = await promisify(fs.readFile)(inputFileDir);
const outputBuffer = await convert({
buffer: inputBuffer,
format: 'PNG',
quality: 1
});
await promisify(fs.writeFile)(outputFileDir, outputBuffer);
console.log(`File converted successfully at: ${outputFileDir}`);
});
});
} catch (error) {
console.log(error);
}
}
convertHEICtoPNG();