You are here

function _drush_imageapi_optimize_batch_optimize_single in Image Optimize (or ImageAPI Optimize) 7.2

Batch callback for optimizing a single image.

1 string reference to '_drush_imageapi_optimize_batch_optimize_single'
drush_imageapi_optimize in ./imageapi_optimize.drush.inc
The ImageAPI Optimize Drush command.

File

./imageapi_optimize.drush.inc, line 148

Code

function _drush_imageapi_optimize_batch_optimize_single($file, $pipeline_name, $backup_dir, &$context) {
  if (isset($backup_dir)) {
    if (file_unmanaged_copy($file, $backup_dir, FILE_EXISTS_RENAME)) {
      drush_log(dt('Backed up file: @file to @destination', array(
        '@file' => $file,
        '@destination' => $backup_dir,
      )));
    }
    else {
      return drush_set_error('Backup of original file failed.');
    }
  }
  drush_log(dt('Optimizing file: @file', array(
    '@file' => $file,
  )));
  $filesize_before = filesize($file);
  imageapi_optimize_optimize_file($pipeline_name, $file);
  clearstatcache(TRUE, $file);
  $filesize_after = filesize($file);
  $context['results']['before'] += $filesize_before;
  $context['results']['after'] += $filesize_after;
  drush_log(dt('Optimized file: @file - saving @bytes', array(
    '@file' => $file,
    '@bytes' => format_size($filesize_before - $filesize_after),
  )), 'ok');
}