| 1 |
<?php |
<?php |
| 2 |
// $Id: canvasactions.inc,v 1.1.4.18 2009/09/05 02:11:58 dman Exp $ |
// $Id: canvasactions.inc,v 1.1.4.19 2009/10/30 14:03:54 dman Exp $ |
| 3 |
/** |
/** |
| 4 |
* @file Helper functions for the text2canvas action for imagecache |
* @file Helper functions for the text2canvas action for imagecache |
| 5 |
* |
* |
| 909 |
* @return a form definition |
* @return a form definition |
| 910 |
*/ |
*/ |
| 911 |
function canvasactions_aspect_form($action) { |
function canvasactions_aspect_form($action) { |
| 912 |
$defaults = array( ); |
$defaults = array( 'ratio_adjustment' => 1 ); |
| 913 |
$action = array_merge($defaults, (array)$action); |
$action = array_merge($defaults, (array)$action); |
| 914 |
|
|
| 915 |
$form = array( |
$form = array( |
| 936 |
'#default_value' => $action['landscape'], |
'#default_value' => $action['landscape'], |
| 937 |
'#options' => $presets, |
'#options' => $presets, |
| 938 |
); |
); |
| 939 |
|
|
| 940 |
|
$form['ratio_adjustment'] = array( |
| 941 |
|
'#type' => 'textfield', |
| 942 |
|
'#title' => t('Ratio Adjustment (advanced)'), |
| 943 |
|
'#size' => 3, |
| 944 |
|
'#default_value' => $action['ratio_adjustment'], |
| 945 |
|
'#description' => t(" |
| 946 |
|
This allows you to bend the rules for how different the proportions need to be to trigger the switch. |
| 947 |
|
<br/>If the (width/height)*n is greater than 1, use 'landscape', otherwise use 'portrait'. |
| 948 |
|
<br/>When n = 1 (the default) it will switch between portrait and landscape modes. |
| 949 |
|
<br/>If n > 1, images that are slightly wide will still be treated as portraits. |
| 950 |
|
If n < 1 then blunt portraits will be treated as landscape. |
| 951 |
|
"), |
| 952 |
|
); |
| 953 |
|
|
| 954 |
|
|
| 955 |
return $form; |
return $form; |
| 956 |
} |
} |
| 957 |
|
|
| 962 |
function theme_canvasactions_aspect($element) { |
function theme_canvasactions_aspect($element) { |
| 963 |
$action = $element['#value']; |
$action = $element['#value']; |
| 964 |
$presets = imagecache_presets(TRUE); |
$presets = imagecache_presets(TRUE); |
| 965 |
return 'Portrait size: <strong>'. $presets[$action['portrait']]['presetname'] . '</strong>. Landscape size: <strong>'. $presets[$action['landscape']]['presetname'] .'</strong>' ; |
$ratio_adjustment = ''; |
| 966 |
|
if ($action['ratio_adjustment'] != 1) { |
| 967 |
|
$ratio_adjustment = " (switch at 1:{$action['ratio_adjustment']})"; |
| 968 |
|
} |
| 969 |
|
return 'Portrait size: <strong>'. $presets[$action['portrait']]['presetname'] . '</strong>. Landscape size: <strong>'. $presets[$action['landscape']]['presetname'] .'</strong>'. $ratio_adjustment ; |
| 970 |
} |
} |
| 971 |
|
|
| 972 |
/** |
/** |
| 979 |
* @param $action |
* @param $action |
| 980 |
*/ |
*/ |
| 981 |
function canvasactions_aspect_image(&$image, $action = array()) { |
function canvasactions_aspect_image(&$image, $action = array()) { |
| 982 |
$preset_id = ($image->info['width'] > $image->info['height'] ) ? $action['landscape'] : $action['portrait']; |
$ratio_adjustment = 0 + $action['ratio_adjustment']; |
| 983 |
|
if (!$ratio_adjustment) { |
| 984 |
|
$ratio_adjustment = 1; |
| 985 |
|
} |
| 986 |
|
$aspect = $image->info['width'] / $image->info['height']; |
| 987 |
|
// width / height * adjustment. If > 1, it's wide. |
| 988 |
|
$preset_id = (($aspect * $ratio_adjustment) > 1) ? $action['landscape'] : $action['portrait']; |
| 989 |
$preset = imagecache_preset($preset_id); |
$preset = imagecache_preset($preset_id); |
| 990 |
|
|
| 991 |
// Run the preset actions ourself. Cannot invoke a preset from the top as it handles filenames, not image objects. |
// Run the preset actions ourself. Cannot invoke a preset from the top as it handles filenames, not image objects. |