You are here

public function ImageAPIOptimizeProcessorJpegOptim::process in Image Optimize (or ImageAPI Optimize) 7.2

Overrides ImageAPIOptimizeProcessorInterface::process

File

plugins/imageapi_optimize/ImageAPIOptimizeProcessorJpegOptim.inc, line 89

Class

ImageAPIOptimizeProcessorJpegOptim

Code

public function process($image, $destination) {
  $cmd = $this
    ->getFullPathToBinary();
  if (empty($cmd)) {
    return FALSE;
  }
  $dst = $this
    ->sanitizeFilename($destination);
  if ($image->info['mime_type'] == 'image/jpeg') {
    $options = array(
      '--quiet',
      '--strip-all',
    );
    $arguments = array(
      $dst,
    );
    if (is_numeric($this
      ->getProgressive())) {
      switch ($this
        ->getProgressive()) {
        case 0:
          $options[] = '--all-normal';
          break;
        case 1:
          $options[] = '--all-progressive';
          break;
      }
    }
    if (is_numeric($this
      ->getQuality())) {
      $options[] = '--max=' . escapeshellarg($this
        ->getQuality());
    }
    if (is_numeric($this
      ->getSize())) {
      $options[] = '--size=' . escapeshellarg($this
        ->getSize() . '%');
    }
    $output = array();
    $return_val = 0;
    $option_string = implode(' ', $options);
    $argument_string = implode(' ', array_map('escapeshellarg', $arguments));
    exec("{$cmd} " . $option_string . ' ' . $argument_string, $output, $return_val);
    if ($return_val == 0) {
      return TRUE;
    }
  }
  return;
}