You are here

public function JpegTran::applyToImage in Image Optimize Binaries 8

Overrides ImageAPIOptimizeProcessorBinaryBase::applyToImage

File

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

Class

JpegTran
Uses the JpegTran 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/jpeg') {
      $options = array(
        '-copy none',
        '-optimize',
      );
      $arguments = array(
        $dst,
      );
      if ($this->configuration['progressive']) {
        $options[] = '-progressive';
      }
      $option_string = implode(' ', $options);
      $argument_string = implode(' ', array_map('escapeshellarg', $arguments));
      return $this
        ->saveCommandStdoutToFile(escapeshellarg($cmd) . ' ' . $option_string . ' ' . $argument_string, $dst);
    }
  }
  return FALSE;
}