class JpegtranFilter

Runs assets through jpegtran.

@link http://jpegclub.org/jpegtran/ @author Kris Wallsmith <kris.wallsmith@gmail.com>

Hierarchy

Expanded class hierarchy of JpegtranFilter

1 file declares its use of JpegtranFilter
JpegtranFilterTest.php in drupal/core/vendor/kriswallsmith/assetic/tests/Assetic/Test/Filter/JpegtranFilterTest.php

File

drupal/core/vendor/kriswallsmith/assetic/src/Assetic/Filter/JpegtranFilter.php, line 24

Namespace

Assetic\Filter
View source
class JpegtranFilter implements FilterInterface {
  const COPY_NONE = 'none';
  const COPY_COMMENTS = 'comments';
  const COPY_ALL = 'all';
  private $jpegtranBin;
  private $optimize;
  private $copy;
  private $progressive;
  private $restart;

  /**
   * Constructor.
   *
   * @param string $jpegtranBin Path to the jpegtran binary
   */
  public function __construct($jpegtranBin = '/usr/bin/jpegtran') {
    $this->jpegtranBin = $jpegtranBin;
  }
  public function setOptimize($optimize) {
    $this->optimize = $optimize;
  }
  public function setCopy($copy) {
    $this->copy = $copy;
  }
  public function setProgressive($progressive) {
    $this->progressive = $progressive;
  }
  public function setRestart($restart) {
    $this->restart = $restart;
  }
  public function filterLoad(AssetInterface $asset) {
  }
  public function filterDump(AssetInterface $asset) {
    $pb = new ProcessBuilder(array(
      $this->jpegtranBin,
    ));
    if ($this->optimize) {
      $pb
        ->add('-optimize');
    }
    if ($this->copy) {
      $pb
        ->add('-copy')
        ->add($this->copy);
    }
    if ($this->progressive) {
      $pb
        ->add('-progressive');
    }
    if (null !== $this->restart) {
      $pb
        ->add('-restart')
        ->add($this->restart);
    }
    $pb
      ->add($input = tempnam(sys_get_temp_dir(), 'assetic_jpegtran'));
    file_put_contents($input, $asset
      ->getContent());
    $proc = $pb
      ->getProcess();
    $code = $proc
      ->run();
    unlink($input);
    if (0 < $code) {
      throw FilterException::fromProcess($proc)
        ->setInput($asset
        ->getContent());
    }
    $asset
      ->setContent($proc
      ->getOutput());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
JpegtranFilter::$copy private property
JpegtranFilter::$jpegtranBin private property
JpegtranFilter::$optimize private property
JpegtranFilter::$progressive private property
JpegtranFilter::$restart private property
JpegtranFilter::COPY_ALL constant
JpegtranFilter::COPY_COMMENTS constant
JpegtranFilter::COPY_NONE constant
JpegtranFilter::filterDump public function Filters an asset just before it's dumped. Overrides FilterInterface::filterDump
JpegtranFilter::filterLoad public function Filters an asset after it has been loaded. Overrides FilterInterface::filterLoad
JpegtranFilter::setCopy public function
JpegtranFilter::setOptimize public function
JpegtranFilter::setProgressive public function
JpegtranFilter::setRestart public function
JpegtranFilter::__construct public function Constructor.