Filters an asset just before it's dumped.
AssetInterface $asset An asset:
Overrides FilterInterface::filterDump
public function filterDump(AssetInterface $asset) {
$pb = new ProcessBuilder(array(
$this->pngoutBin,
));
if (null !== $this->color) {
$pb
->add('-c' . $this->color);
}
if (null !== $this->filter) {
$pb
->add('-f' . $this->filter);
}
if (null !== $this->strategy) {
$pb
->add('-s' . $this->strategy);
}
if (null !== $this->blockSplitThreshold) {
$pb
->add('-b' . $this->blockSplitThreshold);
}
$pb
->add($input = tempnam(sys_get_temp_dir(), 'assetic_pngout'));
file_put_contents($input, $asset
->getContent());
$output = tempnam(sys_get_temp_dir(), 'assetic_pngout');
unlink($output);
$pb
->add($output .= '.png');
$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);
}