/**
* @param $path
*/
public static function optimize($path)
{
$format = getimagesize($path);
if (is_array($format) && array_key_exists("mime", $format)) {
$format = strtolower(str_replace("image/", "", $format["mime"]));
if ($format == "png") {
$optimizer = self::getPngOptimizerCli();
if ($optimizer) {
/*if($optimizer["type"] == "pngquant") {
Console::exec($optimizer["path"] . " --ext xxxoptimized.png " . $path, null, 60);
$newFile = preg_replace("/\.png$/", "", $path);
$newFile .= "xxxoptimized.png";
if(file_exists($newFile)) {
unlink($path);
rename($newFile, $path);
}
} else */
if ($optimizer["type"] == "pngcrush") {
$newFile = $path . ".xxxoptimized";
Console::exec($optimizer["path"] . " " . $path . " " . $newFile, null, 60);
if (file_exists($newFile)) {
unlink($path);
rename($newFile, $path);
}
}
}
} else {
if ($format == "jpeg") {
$optimizer = self::getJpegOptimizerCli();
if ($optimizer) {
if ($optimizer["type"] == "imgmin") {
$newFile = $path . ".xxxoptimized";
Console::exec($optimizer["path"] . " " . $path . " " . $newFile, null, 60);
if (file_exists($newFile)) {
unlink($path);
rename($newFile, $path);
}
} else {
if ($optimizer["type"] == "jpegoptim") {
$additionalParams = "";
if (filesize($path) > 10000) {
$additionalParams = " --all-progressive";
}
Console::exec($optimizer["path"] . $additionalParams . " -o --strip-all --max=85 " . $path, null, 60);
}
}
}
}
}
}
}