lib/image/index.js
function (path, options, callback) {
        var self = this;

        if (typeof options === 'function') {
            callback = options;
            options = undefined;
        }

        _.defaults(options || (options = {}), OPTIM_DEFAULT_OPTIONS);

        var bucks = new Bucks();
        bucks.empty();

        if (REG_OPTIPNG_FILE.test(path) && options.optipng.use) { // optipng
            bucks.add(function(err, res, next) {
                self.optipng(path, options.optipng.options, function(err) {
                    if (err) {
                        logger.error('optipng error.', err);
                        next(err);
                        return;
                    }
                    logger.info('execute optipng:', path);
                    next();
                });
            });
        }

        if (REG_OPTIPNG_FILE.test(path) && options.pngquant.use) { // pngquant
            bucks.add(function(err, res, next) {
                self.pngquant(path, options.pngquant.options, function(err) { // pngquant

                    if (err) {
                        logger.error('pngquant error.', err);
                        next(err);
                        return;
                    }
                    logger.info('execute pngquant:', path);
                    next();

                });
            });
        }

        if (REG_JPEGOPTIM_FILE.test(path) && options.jpegoptim.use) { // jpegoptim
            bucks.add(function(err, res, next) {
                self.jpegoptim(path, options.jpegoptim.options, function(err) {

                    if (err) {
                        logger.error('jpegoptim error.', err);
                        next(err);
                        return;
                    }

                    logger.info('executejpegoptim:', path);
                    next();

                });
            });
        }


        if (bucks._tasks.length === 0) {
            logger.info('no match extension. path: ' + path);
        }

        bucks.end(function(err, ress) {
            callback && callback(err, path);
        });

    }
function (path, options, callback) {
        var self = this;

        if (typeof options === 'function') {
            callback = options;
            options = undefined;
        }

        _.defaults(options || (options = {}), OPTIM_DEFAULT_OPTIONS);

        var bucks = new Bucks();
        bucks.empty();

        if (REG_OPTIPNG_FILE.test(path) && options.optipng.use) { // optipng
            bucks.add(function(err, res, next) {
                self.optipng(path, options.optipng.options, function(err) {
                    if (err) {
                        logger.error('optipng error.', err);
                        next(err);
                        return;
                    }
                    logger.info('execute optipng:', path);
                    next();
                });
            });
        }

        if (REG_OPTIPNG_FILE.test(path) && options.pngquant.use) { // pngquant
            bucks.add(function(err, res, next) {
                self.pngquant(path, options.pngquant.options, function(err) { // pngquant

                    if (err) {
                        logger.error('pngquant error.', err);
                        next(err);
                        return;
                    }
                    logger.info('execute pngquant:', path);
                    next();

                });
            });
        }

        if (REG_JPEGOPTIM_FILE.test(path) && options.jpegoptim.use) { // jpegoptim
            bucks.add(function(err, res, next) {
                self.jpegoptim(path, options.jpegoptim.options, function(err) {

                    if (err) {
                        logger.error('jpegoptim error.', err);
                        next(err);
                        return;
                    }

                    logger.info('executejpegoptim:', path);
                    next();

                });
            });
        }


        if (bucks._tasks.length === 0) {
            logger.info('no match extension. path: ' + path);
        }

        bucks.end(function(err, ress) {
            callback && callback(err, path);
        });

    }
function ( path , options , callback ) { var self = this ; if ( typeof options === 'function' ) { callback = options ; options = undefined ; } _ . defaults ( options || ( options = { } ) , OPTIM_DEFAULT_OPTIONS ) ; var bucks = new Bucks ( ) ; bucks . empty ( ) ; if ( REG_OPTIPNG_FILE . test ( path ) && options . optipng . use ) { // optipng bucks . add ( function ( err , res , next ) { self . optipng ( path , options . optipng . options , function ( err ) { if ( err ) { logger . error ( 'optipng error.' , err ) ; next ( err ) ; return ; } logger . info ( 'execute optipng:' , path ) ; next ( ) ; } ) ; } ) ; } if ( REG_OPTIPNG_FILE . test ( path ) && options . pngquant . use ) { // pngquant bucks . add ( function ( err , res , next ) { self . pngquant ( path , options . pngquant . options , function ( err ) { // pngquant if ( err ) { logger . error ( 'pngquant error.' , err ) ; next ( err ) ; return ; } logger . info ( 'execute pngquant:' , path ) ; next ( ) ; } ) ; } ) ; } if ( REG_JPEGOPTIM_FILE . test ( path ) && options . jpegoptim . use ) { // jpegoptim bucks . add ( function ( err , res , next ) { self . jpegoptim ( path , options . jpegoptim . options , function ( err ) { if ( err ) { logger . error ( 'jpegoptim error.' , err ) ; next ( err ) ; return ; } logger . info ( 'executejpegoptim:' , path ) ; next ( ) ; } ) ; } ) ; } if ( bucks . _tasks . length === 0 ) { logger . info ( 'no match extension. path: ' + path ) ; } bucks . end ( function ( err , ress ) { callback && callback ( err , path ) ; } ) ; }
run the optipng and jpegoptim

@name optim
@memberof image
@method
@param {String} path JPEG|PNG file path.
@param {String} options options.
@param {function} callback
@example
var filepath = './test/image/logo.jpg';
var options = {
optipng:   { use: true, options: "-o 2"},
jpegoptim: { use: true, options: "--strip-all"}
pngquant: { use: true, options: "--ext .png -f -v"}
}
run the optipng and jpegoptim