You are here

ImageAPIOptimizeProcessorPngQuant.inc in Image Optimize (or ImageAPI Optimize) 7.2

File

plugins/imageapi_optimize/ImageAPIOptimizeProcessorPngQuant.inc
View source
<?php

class ImageAPIOptimizeProcessorPngQuant extends ImageAPIOptimizeProcessorBinary implements ImageAPIOptimizeProcessorInterface {
  protected function executableName() {
    return 'pngquant';
  }
  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(
        '--speed=1',
        '--quality=90-99',
        '--force',
        '--ext .png',
      );
      $arguments = array(
        $dst,
      );
      $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;
  }

}