Created
September 13, 2022 13:56
-
-
Save JohnRSim/df1e3d0be51f343020e469ebdce749fc to your computer and use it in GitHub Desktop.
Convert Progressive Jpg to Lossless Jpg
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
/** | |
* 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