beezlib.fsys.walk(config.walkPath, function filefn(prefix, dir, file, stats) { var src = path.join(dir, file); if (!beezlib.image.isResizeImage(src, options)) { return; } bucks.add(function task(err, res, next) { beezlib.image.imagemagick.ratioResize( { srcPath: src, dstPath: dir }, options.baseRatio, options.ratios, function (err, ress) { if (err) { beezlib.logger.error("png resize error. file:", file, 'dir:', dir); beezlib.logger.error(JSON.stringify(err)); process.exit(1); } beezlib.logger.message('\n ', src); for (var i = 0; i < ress.length; i++) { var output = ress[i]; beezlib.logger.message(' ', output.green); } next(); } ); }); });
optim: 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); }); },
bootstrap.ratioResize(function (err, result) { var config = bootstrap.config; config.image = config.image || {}; var options = _.defaults(config.image.options || (config.image.options = {}), DEFAULT_OPTIONS); beezlib.logger.debug('[ start ]'); // -- main beezlib.logger.debug('HOME:', config.HOME); beezlib.logger.debug('locals:', JSON.stringify(config)); beezlib.logger.debug('options:', JSON.stringify(options)); beezlib.logger.message('png/{ratio}.png Resize'.green); beezlib.logger.message(''); beezlib.logger.message(' Base Directory:'.green, config.walkPath || path.dirname(config.sourcePath)); var bucks = new Bucks(); bucks.empty(); if (config.walkPath) { beezlib.fsys.walk(config.walkPath, function filefn(prefix, dir, file, stats) { var src = path.join(dir, file); if (!beezlib.image.isResizeImage(src, options)) { return; } bucks.add(function task(err, res, next) { beezlib.image.imagemagick.ratioResize( { srcPath: src, dstPath: dir }, options.baseRatio, options.ratios, function (err, ress) { if (err) { beezlib.logger.error("png resize error. file:", file, 'dir:', dir); beezlib.logger.error(JSON.stringify(err)); process.exit(1); } beezlib.logger.message('\n ', src); for (var i = 0; i < ress.length; i++) { var output = ress[i]; beezlib.logger.message(' ', output.green); } next(); } ); }); }); } else { var src = config.sourcePath; var dir = path.dirname(src); var file = path.basename(src); bucks.add(function task(err, res, next) { beezlib.image.imagemagick.ratioResize( { srcPath: src, dstPath: dir }, options.baseRatio, options.ratios, function (err, ress) { if (err) { beezlib.logger.error("png resize error. file:", file, 'dir:', dir); beezlib.logger.error(JSON.stringify(err)); process.exit(1); } beezlib.logger.message('\n ', src); for (var i = 0; i < ress.length; i++) { var output = ress[i]; beezlib.logger.message(' ', output.green); } next(); } ); }); } bucks.end(function(err, ress) { if (err) { beezlib.logger.error(JSON.stringify(err)); process.exit(1); } beezlib.logger.message('\n'); beezlib.logger.message('finished.\n'); }); });