function canvasactions_aspect_image in ImageCache Actions 6.2
Same name and namespace in other branches
- 6 canvasactions.inc \canvasactions_aspect_image()
Choose the action and trigger that.
Implementation of hook_image()
Parameters
$image:
$action:
File
- canvasactions/
canvasactions.inc, line 786
Code
function canvasactions_aspect_image(&$image, $action = array()) {
$ratio_adjustment = 0 + $action['ratio_adjustment'];
if (!$ratio_adjustment) {
$ratio_adjustment = 1;
}
$aspect = $image->info['width'] / $image->info['height'];
// width / height * adjustment. If > 1, it's wide.
$preset_name = $aspect * $ratio_adjustment > 1 ? $action['landscape'] : $action['portrait'];
$preset = imagecache_preset_by_name($preset_name);
if (empty($preset)) {
// Required preset has gone missing?
watchdog('imagecache_canvasactions', "When running 'aspect' action, I was unable to load sub-action %preset_name. Either it's been deleted or the DB needs an update", array(
'%preset_name' => $preset_name,
), WATCHDOG_ERROR);
return FALSE;
}
// Run the preset actions ourself. Cannot invoke a preset from the top as it handles filenames, not image objects.
// ripped from imagecache_build_derivative()
foreach ($preset['actions'] as $sub_action) {
// _imagecache_apply_action requires some of the values to be pre-cooked
// Identified in http://drupal.org/node/626168
// These actions really should interpret the parameters themselves.
foreach (array(
'height',
'width',
) as $param) {
if (isset($sub_action['data'][$param])) {
$sub_action['data'][$param] = _imagecache_percent_filter($sub_action['data'][$param], $image->info[$param]);
}
}
foreach (array(
'xoffset' => 'width',
'yoffset' => 'height',
) as $param => $direction) {
if (isset($sub_action['data'][$param])) {
$sub_action['data'][$param] = _imagecache_keyword_filter($sub_action['data'][$param], $image->info[$direction], $sub_action['data'][$direction]);
}
}
_imagecache_apply_action($sub_action, $image);
}
return TRUE;
}