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; }