You are here

function canvasactions_aspect_effect in ImageCache Actions 8

Same name and namespace in other branches
  1. 7 canvasactions/canvasactions.inc \canvasactions_aspect_effect()

Image effect callback for the aspect switcher effect.

Parameters

stdClass $image:

array $data:

Return value

boolean true on success, false otherwise.

1 string reference to 'canvasactions_aspect_effect'
imagecache_canvasactions_image_effect_info in canvasactions/imagecache_canvasactions.module
Implements hook_image_effect_info().

File

canvasactions/canvasactions.inc, line 901

Code

function canvasactions_aspect_effect(stdClass $image, array $data) {
  $ratio_adjustment = isset($data['ratio_adjustment']) ? floatval($data['ratio_adjustment']) : 1;
  $aspect = $image->info['width'] / $image->info['height'];

  // width / height * adjustment. If > 1, it's wide.
  $style_name = $aspect * $ratio_adjustment > 1 ? $data['landscape'] : $data['portrait'];
  if (empty($style_name)) {

    // Do nothing. just return what we've got.
    return TRUE;
  }
  $style = image_style_load($style_name);
  if (empty($style)) {

    // Required preset has gone missing?
    watchdog('imagecache_actions', "When running 'aspect' action, I was unable to load sub-action %style_name. Either it's been deleted or the DB needs an update", array(
      '%style_name' => $style_name,
    ), WATCHDOG_ERROR);
    return FALSE;
  }

  // Run the preset actions ourself.
  foreach ($style['effects'] as $sub_effect) {
    image_effect_apply($image, $sub_effect);
  }
  return TRUE;
}