Skip to content

Instantly share code, notes, and snippets.

@icavalheiro
Created May 22, 2024 15:23
Show Gist options
  • Save icavalheiro/493cdcf3401243b39b0bf099eba1b2a3 to your computer and use it in GitHub Desktop.
Save icavalheiro/493cdcf3401243b39b0bf099eba1b2a3 to your computer and use it in GitHub Desktop.
Convert iphone's HEIC files in a folder into JPEGs (its slow)
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