Runs assets through Jpegoptim.
@link http://www.kokkonen.net/tjko/projects.html @author Kris Wallsmith <kris.wallsmith@gmail.com>
Expanded class hierarchy of JpegoptimFilter
class JpegoptimFilter implements FilterInterface {
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 = new ProcessBuilder(array(
$this->jpegoptimBin,
));
if ($this->stripAll) {
$pb
->add('--strip-all');
}
if ($this->max) {
$pb
->add('--max=' . $this->max);
}
$pb
->add($input = tempnam(sys_get_temp_dir(), 'assetic_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);
}
}
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
JpegoptimFilter:: |
private | property | ||
JpegoptimFilter:: |
private | property | ||
JpegoptimFilter:: |
private | property | ||
JpegoptimFilter:: |
public | function |
Filters an asset just before it's dumped. Overrides FilterInterface:: |
|
JpegoptimFilter:: |
public | function |
Filters an asset after it has been loaded. Overrides FilterInterface:: |
|
JpegoptimFilter:: |
public | function | ||
JpegoptimFilter:: |
public | function | ||
JpegoptimFilter:: |
public | function | Constructor. |