You are here

public function OptiPng::applyToImage in Image Optimize Binaries 8

Overrides ImageAPIOptimizeProcessorBinaryBase::applyToImage

File

src/Plugin/ImageAPIOptimizeProcessor/OptiPng.php, line 26

Class

OptiPng
Uses the OptiPng binary to optimize images.

Namespace

Drupal\imageapi_optimize_binaries\Plugin\ImageAPIOptimizeProcessor

Code

public function applyToImage($image_uri) {
  if ($cmd = $this
    ->getFullPathToBinary()) {
    $dst = $this
      ->sanitizeFilename($image_uri);
    if ($this
      ->getMimeType($image_uri) == 'image/png') {
      $options = array(
        '--quiet',
      );
      $arguments = array(
        $dst,
      );
      if (is_numeric($this->configuration['interlace'])) {
        $options[] = '-i ' . $this->configuration['interlace'];
      }
      $options[] = '-o' . $this->configuration['level'];
      return $this
        ->execShellCommand($cmd, $options, $arguments);
    }
  }
  return FALSE;
}