Created
May 22, 2024 15:23
-
-
Save icavalheiro/493cdcf3401243b39b0bf099eba1b2a3 to your computer and use it in GitHub Desktop.
Convert iphone's HEIC files in a folder into JPEGs (its slow)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs').promises | |
const path = require('path') | |
const convert = require('heic-convert') | |
async function getFiles(folder){ | |
const filesFound = await fs.readdir(folder) | |
const files = [] | |
filesFound.forEach(file => { | |
files.push(path.join(folder, file)) | |
}) | |
return files | |
} | |
async function convertFile(file){ | |
const input = await fs.readFile(file) | |
const output = await convert({ | |
buffer: input, | |
format: "JPEG", | |
quality: 1 | |
}); | |
await fs.writeFile(file + ".jpg", output) | |
} | |
async function run(){ | |
const dir = "/path/to/the/folder/" | |
const files = await getFiles(dir); | |
for(let i = 0; i < files.length; i ++){ | |
await convertFile(files[i]) | |
} | |
} | |
run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment