You are here

function canvasactions_aspect_form in ImageCache Actions 6.2

Same name and namespace in other branches
  1. 8 canvasactions/canvasactions.inc \canvasactions_aspect_form()
  2. 6 canvasactions.inc \canvasactions_aspect_form()
  3. 7 canvasactions/canvasactions.inc \canvasactions_aspect_form()

Switch between presets depending on logic

Implementation of imagecache_hook_form()

Parameters

$action array of settings for this action:

Return value

a form definition

File

canvasactions/canvasactions.inc, line 712

Code

function canvasactions_aspect_form($action) {
  $defaults = array(
    'ratio_adjustment' => 1,
    'portrait' => NULL,
    'landscape' => NULL,
  );
  $action = array_merge($defaults, (array) $action);
  $form = array(
    'help' => array(
      '#type' => 'markup',
      '#value' => t('You must create the two presets to use <em>before</em> enabling this process.'),
    ),
  );
  $presets = array();
  foreach (imagecache_presets(TRUE) as $preset) {
    $presets[$preset['presetname']] = $preset['presetname'];
  }
  $form['portrait'] = array(
    '#type' => 'select',
    '#title' => t('Preset to use if the image is portrait (vertical)'),
    '#default_value' => $action['portrait'],
    '#options' => $presets,
  );
  $form['landscape'] = array(
    '#type' => 'select',
    '#title' => t('Preset to use if the image is landscape (horizontal)'),
    '#default_value' => $action['landscape'],
    '#options' => $presets,
  );
  $form['ratio_adjustment'] = array(
    '#type' => 'textfield',
    '#title' => t('Ratio Adjustment (advanced)'),
    '#size' => 3,
    '#default_value' => $action['ratio_adjustment'],
    '#description' => t("\nThis allows you to bend the rules for how different the proportions need to be to trigger the switch.  \n<br/>If the (width/height)*n is greater than 1, use 'landscape', otherwise use 'portrait'.\n<br/>When n = 1 (the default) it will switch between portrait and landscape modes.\n<br/>If n > 1, images that are slightly wide will still be treated as portraits.\nIf n < 1 then blunt portraits will be treated as landscape.\n    "),
  );
  return $form;
}