Created
April 10, 2012 15:48
-
-
Save devster/2352307 to your computer and use it in GitHub Desktop.
Jpegoptim driver for npAssetsOptimizerPlugin for sf1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class npDriverJpegoptim extends npDriverBase | |
{ | |
public function doProcessFile($file, $replace = false) | |
{ | |
if (false === $replace) | |
{ | |
throw new LogicException('JPEG optimization only support file replacement atm'); | |
} | |
exec('which jpegoptim', $output, $return); | |
if (!count($output) || $return > 0) | |
{ | |
throw new RuntimeException('The jpegoptim program is not available nor accessible by php on your system'); | |
} | |
$command = sprintf('jpegoptim --strip-all -m90 %s', escapeshellarg($file)); | |
exec($command, $output, $return); | |
if ($return > 0) | |
{ | |
throw new RuntimeException(sprintf("Error status code %d received while executing command: %s", $return, $command)); | |
} | |
return $file; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment