You are here

function _imageapi_optimize_service_internal in Image Optimize (or ImageAPI Optimize) 6

Uses internal tools to optimize

File

./imageapi_optimize.module, line 206
Image optimize functionalities

Code

function _imageapi_optimize_service_internal($image, $dst) {
  switch ($image->info['mime_type']) {
    case 'image/png':
      if ($cmd = variable_get('imageapi_optimize_optipng', '')) {
        exec("{$cmd} -o5 -quiet " . escapeshellarg($dst));
      }
      if ($cmd = variable_get('imageapi_optimize_pngcrush', '')) {
        $temp = tempnam(realpath(file_directory_temp()), 'file');
        exec("{$cmd} -rem alla -reduce -brute -q " . escapeshellarg($dst) . " " . escapeshellarg($temp) . " && mv " . escapeshellarg($temp) . " " . escapeshellarg($dst));
      }
      if ($cmd = variable_get('imageapi_optimize_advpng', '')) {
        exec("{$cmd} -z4q " . escapeshellarg($dst));
      }
      break;
    case 'image/jpeg':
      if ($cmd = variable_get('imageapi_optimize_jpegtran', '')) {
        _imageapi_optimize_exec("{$cmd} -copy none -optimize " . escapeshellarg($dst), $dst);
      }
      if ($cmd = variable_get('imageapi_optimize_jfifremove', '')) {
        _imageapi_optimize_exec("{$cmd} < " . escapeshellarg($dst), $dst);
      }
      break;
  }
  return TRUE;
}