Filters an asset just before it's dumped.
AssetInterface $asset An asset:
Overrides FilterInterface::filterDump
public function filterDump(AssetInterface $asset) {
$pb = $this
->createProcessBuilder(array(
$this->optipngBin,
));
if (null !== $this->level) {
$pb
->add('-o')
->add($this->level);
}
$pb
->add('-out')
->add($output = tempnam(sys_get_temp_dir(), 'assetic_optipng'));
unlink($output);
$pb
->add($input = tempnam(sys_get_temp_dir(), 'assetic_optipng'));
file_put_contents($input, $asset
->getContent());
$proc = $pb
->getProcess();
$code = $proc
->run();
if (0 !== $code) {
unlink($input);
throw FilterException::fromProcess($proc)
->setInput($asset
->getContent());
}
$asset
->setContent(file_get_contents($output));
unlink($input);
unlink($output);
}