You are here

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

Overrides ImageAPIOptimizeProcessorInterface::process

File

plugins/imageapi_optimize/ImageAPIOptimizeProcessorOptiPng.inc, line 65

Class

ImageAPIOptimizeProcessorOptiPng

Code

public function process($image, $destination) {
  $cmd = $this
    ->getFullPathToBinary();
  if (empty($cmd)) {
    return FALSE;
  }
  $dst = $this
    ->sanitizeFilename($destination);
  if ($image->info['mime_type'] == 'image/png') {
    $options = array(
      '--quiet',
    );
    $arguments = array(
      $dst,
    );
    if (is_numeric($this
      ->getInterlace())) {
      $options[] = '-i ' . $this
        ->getInterlace();
    }
    $options[] = '-o' . $this
      ->getLevel();
    $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;
}