Issue
Ive been trying to convert a series of images, PNG to JPG, and I seem to run into an issue where the output media is outputted to the intended path and the path of the code main script:
module used: npm media-converter
Code:
/**
* Reads PNG File(s) then converts to JPG
*/
function ArrayConvertPNGtoJPG() {
// PNG to JPG Spinner
const pngTOjpgSpinner = ora("WARNING: Attempting Conversion of PNG to JPG").start();
const directoryPath = path.join(__dirname, './Input');
setTimeout(() => {
fs.readdir(directoryPath, function (err, files) {
//handling error
if (err) {
return console.log('Unable to scan directory: ' + err);
}
for (let i = 0; i < files.length; i++) {
const input = "./Input/" + files[i];
const output = `./Converted/${files[i].slice(0, -4)}.jpg`
convert(input, output, (err) => {
if (!err){
pngTOjpgSpinner.succeed("SUCCESS: ".green + input.green + " Converted to ".green + output.green);
} else {
pngTOjpgSpinner.fail("ERROR: Unable to convert file: " + input + " to a JPG");
}
});
}
});
}, 2000);
}
Result:
If you could help me find a solution it would be helpful.
from Output Media is outputted to 2 Directories instead of 1
No comments:
Post a Comment