Skip to content

Instantly share code, notes, and snippets.

@devster
Created April 10, 2012 15:48
Show Gist options
  • Save devster/2352307 to your computer and use it in GitHub Desktop.
Save devster/2352307 to your computer and use it in GitHub Desktop.
Jpegoptim driver for npAssetsOptimizerPlugin for sf1
<?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