static function install()
 {
     $defaults = array('jpg' => '1', 'png' => '2', 'gif' => '1');
     foreach ($defaults as $type => $optlevel) {
         // set default path as the pre-compiled versions in the lib
         module::set_var("image_optimizer", "path_" . $type, MODPATH . "image_optimizer/lib/" . image_optimizer::tool_name($type));
         // check config status (also sets configstatus_ variables and ensures that the permissions are set correctly)
         image_optimizer::tool_status($type);
         // set default optimization levels
         module::set_var("image_optimizer", "optlevel_thumb_" . $type, $optlevel);
         module::set_var("image_optimizer", "optlevel_resize_" . $type, $optlevel);
     }
     module::set_var("image_optimizer", "rotate_jpg", true);
     module::set_var("image_optimizer", "enable_thumb", true);
     module::set_var("image_optimizer", "enable_resize", true);
     module::set_var("image_optimizer", "update_mode_thumb", false);
     module::set_var("image_optimizer", "update_mode_resize", false);
     module::set_var("image_optimizer", "metastrip_thumb", true);
     module::set_var("image_optimizer", "convert_thumb_png", "jpg");
     module::set_var("image_optimizer", "convert_resize_png", false);
     module::set_var("image_optimizer", "convert_thumb_gif", "jpg");
     module::set_var("image_optimizer", "convert_resize_gif", false);
     module::set_var("image_optimizer", "metastrip_resize", false);
     module::set_var("image_optimizer", "progressive_thumb", false);
     module::set_var("image_optimizer", "progressive_resize", true);
     module::set_version("image_optimizer", 1);
     image_optimizer::add_image_optimizer_rule("thumb");
     image_optimizer::add_image_optimizer_rule("resize");
 }
 static function tool_version($type)
 {
     $type = strtolower($type);
     if (image_optimizer::tool_status($type)) {
         switch ($type) {
             case "jpg":
                 $path = module::get_var("image_optimizer", "path_" . $type);
                 // jpegtran is weird as it doesn't have a version flag.  so, we run in verbose mode with a fake file and catch stderr, which exec() can't do.
                 // this is sort of a hack, but since there's no clean way available...
                 $cmd = escapeshellcmd($path) . " -verbose " . MODPATH . "image_optimizer/this_file_does_not_exist.jpg";
                 $output = image_optimizer::get_pipe($cmd, 2);
                 $output = "Correctly configured! " . substr($output, 0, strpos($output, "\n"));
                 break;
             case "png":
             case "gif":
                 $path = module::get_var("image_optimizer", "path_" . $type);
                 exec(escapeshellcmd($path) . " --version", $output);
                 $output = "Correctly configured!  " . $output[0];
                 break;
             default:
                 $output = t("Only jpg/png/gif supported");
         }
     } else {
         $output = t("Invalid configuration");
     }
     return $output;
 }