Last active
May 21, 2018 13:11
-
-
Save Antoinebr/0de2510a055da3ebfb99931ac6e4ed77 to your computer and use it in GitHub Desktop.
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
const glob = require("glob") | |
const util = require('util'); | |
const exec = util.promisify(require('child_process').exec); | |
// Updte with your image path | |
const yourImagesPath = "/home/mobileui/app/wp-content/uploads/2018/01/*.jpg"; | |
glob(yourImagesPath, {}, function (er, files) { | |
if( er ) throw new Error( er ); | |
if( files.length === 0) throw new Error( 'No Files found' ); | |
files.forEach( path => { | |
// Be sure that "cjpeg" is in your path | |
exec(`cjpeg -quality 60 -outfile ${path}.min.jpg -optimise ${path}`) | |
.then( res => console.log(`Compression OK : ${path}`)) | |
.then( res => exec(`mv ${path}.min.jpg ${path}`)) | |
.then( res => console.log(`Renaming OK : ${path}`)) | |
.catch( stderr => console.log('Error ', stderr)) | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You have to install glob
npm install glob