Skip to content

Instantly share code, notes, and snippets.

@emersonbroga
Last active October 25, 2022 13:28
Show Gist options
  • Save emersonbroga/91dd99d31f14d92530eba9451bda4608 to your computer and use it in GitHub Desktop.
Save emersonbroga/91dd99d31f14d92530eba9451bda4608 to your computer and use it in GitHub Desktop.
Convert images from CR2 to JPG.

Conversor de imagens de CR2 para JPG

instruções

salve o código como index.js crie uma pasta chamada CR2 adicione os seus arquivos CR2 la crie uma pasta chamada JPG e deixe ela vazia abra o seu terminal e rode npm install --save cr2-raw depois rode node index.js

convert images from CR2 to JPG

instructions

save the code as index.js create a folder called CR2 and add your CR2 files there. create a folder called JPG and leave it empty open your terminal and run npm install --save cr2-raw then run node index.js

DEMO

http://s3.emerson.link/prints/2020-06-23-215157-7kxcv.mp4

const cr2Raw = require('cr2-raw');
const fs = require('fs');
const convert = (source, destination) => new Promise((resolve, reject)=> {
try{
const raw = cr2Raw(source);
fs.writeFileSync(destination, raw.previewImage());
}catch(error){
console.log(error);
resolve(null);
}
});
const sourceFolder = './CR2';
const destinationFolder = './JPG';
fs.readdir(sourceFolder, (err, files) => {
const convertCalls = files.map((file) => {
const source = `${sourceFolder}/${file}`;
const destination = `${destinationFolder}/${file}`.replace('.CR2', '.jpg');
return convert(source, destination);
});
Promise.all(convertCalls, console.log);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment