function canvasactions_aspect_dimensions in ImageCache Actions 8
Same name and namespace in other branches
- 7 canvasactions/canvasactions.inc \canvasactions_aspect_dimensions()
Image dimensions callback for the aspect switcher effect.
Parameters
array $dimensions: Dimensions to be modified - an associative array containing the items 'width' and 'height' (in pixels).
array $data: An associative array containing the effect data.
1 string reference to 'canvasactions_aspect_dimensions'
- imagecache_canvasactions_image_effect_info in canvasactions/
imagecache_canvasactions.module - Implements hook_image_effect_info().
File
- canvasactions/
canvasactions.inc, line 937
Code
function canvasactions_aspect_dimensions(array &$dimensions, array $data) {
if (!isset($dimensions['width']) || !isset($dimensions['height'])) {
// We cannot know which preset would be executed and thus cannot know the
// resulting dimensions, unless both styles return the same dimensions:
$landscape_dimensions = $portrait_dimensions = $dimensions;
image_style_transform_dimensions($data['landscape'], $landscape_dimensions);
image_style_transform_dimensions($data['portrait'], $portrait_dimensions);
if ($landscape_dimensions == $portrait_dimensions) {
$dimensions = $landscape_dimensions;
}
else {
$dimensions['width'] = $dimensions['height'] = NULL;
}
}
else {
$ratio_adjustment = isset($data['ratio_adjustment']) ? floatval($data['ratio_adjustment']) : 1;
$aspect = $dimensions['width'] / $dimensions['height'];
$style_name = $aspect * $ratio_adjustment > 1 ? $data['landscape'] : $data['portrait'];
image_style_transform_dimensions($style_name, $dimensions);
}
}