Skip to content

Instantly share code, notes, and snippets.

@JohnRSim
Created September 13, 2022 13:56
Show Gist options
  • Save JohnRSim/df1e3d0be51f343020e469ebdce749fc to your computer and use it in GitHub Desktop.
Save JohnRSim/df1e3d0be51f343020e469ebdce749fc to your computer and use it in GitHub Desktop.
Convert Progressive Jpg to Lossless Jpg
/**
* convert
* Add any custom Image conversion logic
* @param {String} assetPath file path to convert image
* @returns {String} string path to converted image
*/
async function convert(assetPath) {
return new Promise(async (resolve, reject) => {
const outputPath = assetPath.replace(/media/g,'output');
//convert image and change from progressive to lossless
sharp(assetPath)
.withMetadata() //keep all image data
//.resize(300, 200)
.toFile(outputPath, (err) => {
if (err) {
console.log('err:', err);
reject();
} else {
resolve(outputPath);
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment