*/ class JpegoptimFilter extends BaseProcessFilter { private $jpegoptimBin; private $stripAll; private $max; /** * 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 setMax($max) { $this->max = $max; } public function filterLoad(AssetInterface $asset) { } public function filterDump(AssetInterface $asset) { $pb = $this->createProcessBuilder(array($this->jpegoptimBin)); if ($this->stripAll) { $pb->add('--strip-all'); } if ($this->max) { $pb->add('--max='.$this->max); } $pb->add($input = FilesystemUtils::createTemporaryFile('jpegoptim')); file_put_contents($input, $asset->getContent()); $proc = $pb->getProcess(); $proc->run(); if (false !== strpos($proc->getOutput(), 'ERROR')) { unlink($input); throw FilterException::fromProcess($proc)->setInput($asset->getContent()); } $asset->setContent(file_get_contents($input)); unlink($input); } }