示例#1
0
 public static function minify_images()
 {
     $path = Cli::addOption("path", WWW_PATH, "Path where to find images");
     $norun = Cli::addSwitch("n", "Do not run the scripts, only print files to process");
     Cli::enableHelp();
     Cli::pinfo("Minify images");
     foreach (self::globRecursive($path . "/*.[pP][nN][gG]", GLOB_NOSORT) as $png) {
         Cli::pinfo(" * {$png}");
         $output = "";
         $return_var = -1;
         $cmd = "pngcrush -ow -brute -reduce {$png}";
         if ($norun) {
             Logger::Debug("   > {$cmd}");
         } else {
             exec("{$cmd} 2>& 1", $output, $return_var);
             if ($return_var != 0) {
                 Cli::perr(implode($output, "\n"));
             } else {
                 Logger::Debug(implode($output, "\n"));
             }
         }
     }
     foreach (self::globRecursive($path . "/{*.[jJ][pP][gG], *.[jJ][pP][eE][gG]}", GLOB_BRACE | GLOB_NOSORT) as $jpg) {
         Cli::pinfo(" * {$jpg}");
         $output = "";
         $return_var = -1;
         $cmd = "jpegoptim -s -v -v {$jpg}";
         if ($norun) {
             Logger::Debug("   > {$cmd}");
         } else {
             exec("{$cmd} 2>& 1", $output, $return_var);
             if ($return_var != 0) {
                 Cli::perr(implode($output, "\n"));
             } else {
                 Logger::Debug(implode($output, "\n"));
             }
         }
     }
 }