*/ class JpegoptimFilter implements FilterInterface { private $jpegoptimBin; private $stripAll; /** * Constructor. * * @param string $jpegoptimBin Path to the jpegoptim binary */ public function __construct($jpegoptimBin = '/usr/bin/jpegoptim') { $this->jpegoptimBin = $jpegoptimBin; } public function setStripAll($stripAll) { $this->stripAll = $stripAll; } public function filterLoad(AssetInterface $asset) { } public function filterDump(AssetInterface $asset) { $options = array($this->jpegoptimBin); if ($this->stripAll) { $options[] = '--strip-all'; } $options[] = $input = tempnam(sys_get_temp_dir(), 'assetic_jpegoptim'); file_put_contents($input, $asset->getContent()); $proc = new Process(implode(' ', array_map('escapeshellarg', $options))); $proc->run(); if (false !== strpos($proc->getOutput(), 'ERROR')) { unlink($input); throw new \RuntimeException($proc->getOutput()); } $asset->setContent(file_get_contents($input)); unlink($input); } }