*/ class OptiPngFilter implements FilterInterface { private $optipngBin; private $level; /** * Constructor. * * @param string $optipngBin Path to the optipng binary */ public function __construct($optipngBin = '/usr/bin/optipng') { $this->optipngBin = $optipngBin; } public function setLevel($level) { $this->level = $level; } public function filterLoad(AssetInterface $asset) { } public function filterDump(AssetInterface $asset) { $options = array($this->optipngBin); if (null !== $this->level) { $options[] = '-o'; $options[] = $this->level; } $options[] = '-out'; $options[] = $output = tempnam(sys_get_temp_dir(), 'assetic_optipng'); unlink($output); $options[] = $input = tempnam(sys_get_temp_dir(), 'assetic_optipng'); file_put_contents($input, $asset->getContent()); $proc = new Process(implode(' ', array_map('escapeshellarg', $options))); $code = $proc->run(); if (0 < $code) { unlink($input); throw new \RuntimeException($proc->getOutput()); } $asset->setContent(file_get_contents($output)); unlink($input); unlink($output); } }