You are here

function _imagecache_actions_form in ImageCache 5

1 call to _imagecache_actions_form()
imagecache_admin in ./imagecache.module

File

./imagecache.module, line 604
Dynamic image resizer and image cacher.

Code

function _imagecache_actions_form($presetid) {
  $form = array();
  $actions = _imagecache_actions_get_by_presetid($presetid);
  foreach ($actions as $actionid => $action) {

    //debug_msg($action);
    $form[$actionid] = array(
      '#type' => 'fieldset',
      '#title' => t($action['data']['function']),
    );
    $form[$actionid]['data']['function'] = array(
      '#type' => 'hidden',
      '#value' => $action['data']['function'],
    );
    $form[$actionid]['weight'] = array(
      '#type' => 'weight',
      '#title' => t('Weight'),
      '#default_value' => $action['weight'],
    );
    switch ($action['data']['function']) {
      case 'scale':
        $helptext = array();
        $helptext['inside'] = t('<strong>Inside dimensions</strong>: Final dimensions will be less than or equal to the entered width and height. Useful for ensuring a maximum height and/or width.');
        $helptext['outside'] = t('<strong>Outside dimensions</strong>: Final dimensions will be greater than or equal to the entered width and height. Ideal for cropping the result to a square.');
        $description = '<ul><li>' . implode('</li><li>', $helptext) . '</li><ul>';
        $form[$actionid]['data']['fit'] = array(
          '#type' => 'select',
          '#title' => t('Scale to fit'),
          '#options' => array(
            'inside' => t('Inside dimensions'),
            'outside' => t('Outside dimensions'),
          ),
          '#default_value' => $action['data']['fit'],
          '#weight' => 1,
          '#description' => $description,
        );
      case 'resize':
        $form[$actionid]['data']['width'] = array(
          '#type' => 'textfield',
          '#title' => t('Width'),
          '#default_value' => $action['data']['width'],
          '#description' => t('Enter a width in pixels or as a percentage. i.e. 500 or 80%.'),
        );
        $form[$actionid]['data']['height'] = array(
          '#type' => 'textfield',
          '#title' => t('Height'),
          '#default_value' => $action['data']['height'],
          '#description' => t('Enter a height in pixels or as a percentage. i.e. 500 or 80%.'),
        );
        break;
      case 'crop':
        $form[$actionid]['data']['width'] = array(
          '#type' => 'textfield',
          '#title' => t('Width'),
          '#default_value' => $action['data']['width'],
          '#description' => t('Enter a width in pixels or as a percentage. i.e. 500 or 80%.'),
        );
        $form[$actionid]['data']['height'] = array(
          '#type' => 'textfield',
          '#title' => t('Height'),
          '#default_value' => $action['data']['height'],
          '#description' => t('Enter a height in pixels or as a percentage. i.e. 500 or 80%.'),
        );
        $form[$actionid]['data']['xoffset'] = array(
          '#type' => 'textfield',
          '#title' => t('X offset'),
          '#default_value' => $action['data']['xoffset'],
          '#description' => t('Enter an offset in pixels or use a keyword: <em>left</em>, <em>center</em>, or <em>right</em>.'),
        );
        $form[$actionid]['data']['yoffset'] = array(
          '#type' => 'textfield',
          '#title' => t('Y offset'),
          '#default_value' => $action['data']['yoffset'],
          '#description' => t('Enter an offset in pixels or use a keyword: <em>top</em>, <em>center</em>, or <em>bottom</em>.'),
        );
        break;
      case 'watermark':
    }
    $form[$actionid]['remove'] = array(
      '#type' => 'checkbox',
      '#title' => t('Remove this action'),
    );
  }
  $helptext = array();
  $helptext['scale'] = t('<strong>Scale</strong>: Resize an image maintaining the original aspect-ratio (only one value necessary).');
  $helptext['resize'] = t('<strong>Resize</strong>: Resize an image to an exact set of dimensions, ignoring aspect ratio.');
  $helptext['crop'] = t('<strong>Crop</strong>: Crop an image to the rectangle specified by the given offsets and dimensions.');
  $description = '<ul><li>' . implode('</li><li>', $helptext) . '</li><ul>';
  $form['newaction'] = array(
    '#type' => 'select',
    '#options' => array(
      '' => t('select...'),
      'scale' => t('Scale'),
      'resize' => t('Resize'),
      'crop' => t('Crop'),
    ),
    '#title' => t('Add a new action'),
    '#description' => $description,
  );
  return $form;
}