You are here

function image_imageapi_optimize_save in Image Optimize (or ImageAPI Optimize) 7.2

Same name and namespace in other branches
  1. 7 imageapi_optimize.module \image_imageapi_optimize_save()

Implements image_HOOK_save().

File

./imageapi_optimize.module, line 747

Code

function image_imageapi_optimize_save(stdClass $image, $destination) {

  // This property is set by imageapi_optimize_optimize_processor().
  if (isset($image->imageapi_optimize_original_toolkit) && isset($image->imageapi_optimize_pipeline) && $image->toolkit != $image->imageapi_optimize_original_toolkit) {

    // Cleanup our $image object.
    $original_toolkit = $image->imageapi_optimize_original_toolkit;
    $pipeline = $image->imageapi_optimize_pipeline;
    unset($image->imageapi_optimize_original_toolkit);
    unset($image->imageapi_optimize_pipeline);
    $image->toolkit = $original_toolkit;

    // Save the image with the original toolkit, and then optimize.
    if (image_toolkit_invoke('save', $image, array(
      $destination,
    ))) {
      imageapi_optimize_optimize_file($pipeline, $destination, $image);

      // Failure to optimize means the original image will still be in place.
      return TRUE;
    }
  }
  return FALSE;
}