You are here

function canvasactions_roundedcorners_form in ImageCache Actions 8

Same name and namespace in other branches
  1. 5.3 canvasactions.inc \canvasactions_roundedcorners_form()
  2. 5.2 canvasactions.inc \canvasactions_roundedcorners_form()
  3. 6.2 canvasactions/rounded_corners.inc \canvasactions_roundedcorners_form()
  4. 6 canvasactions.inc \canvasactions_roundedcorners_form()
  5. 7 canvasactions/rounded_corners.inc \canvasactions_roundedcorners_form()

Set radius for corner rounding

Implementation of imagecache_hook_form()

Parameters

$action array of settings for this action:

Return value

a form definition

1 string reference to 'canvasactions_roundedcorners_form'
imagecache_canvasactions_image_effect_info in canvasactions/imagecache_canvasactions.module
Implements hook_image_effect_info().

File

canvasactions/rounded_corners.inc, line 15
Routines for rounded corners

Code

function canvasactions_roundedcorners_form($action) {
  if (image_get_toolkit() != 'gd') {
    drupal_set_message('Rounded corners are not currently supported on all versions of imagemagick. This effect works best with GD image toolkit only.', 'warning');
  }
  drupal_add_js(drupal_get_path('module', 'imagecache_actions') . '/imagecache_actions.jquery.js');
  $defaults = array(
    'radius' => '16',
    #'antialias' => TRUE,
    'independent_corners_set' => array(
      'independent_corners' => FALSE,
      'radii' => array(
        'tl' => 0,
        'tr' => 0,
        'bl' => 0,
        'br' => 0,
      ),
    ),
  );
  $action = array_merge($defaults, (array) $action);
  $form['radius'] = array(
    '#type' => 'textfield',
    '#title' => t('radius'),
    '#default_value' => $action['radius'],
    '#size' => 2,
  );
  $form['independent_corners_set'] = array(
    '#type' => 'fieldset',
    '#title' => t('Individual Corner Values'),
    '#collapsible' => TRUE,
    '#collapsed' => !$action['independent_corners_set']['independent_corners'],
  );
  $form['independent_corners_set']['independent_corners'] = array(
    '#type' => 'checkbox',
    '#title' => t('Set Corners Independently'),
    '#default_value' => $action['independent_corners_set']['independent_corners'],
  );
  $corners = array(
    'tl' => t("Top Left Radius"),
    'tr' => t("Top Right Radius"),
    'bl' => t("Bottom Left Radius"),
    'br' => t("Bottom Right Radius"),
  );

  // Loop over the four corners and create field elements for them.
  $form['independent_corners_set']['radii'] = array(
    '#type' => 'item',
    '#id' => 'independent-corners-set',
    '#states' => array(
      'visible' => array(
        ':input[name="data[independent_corners_set][independent_corners]"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );
  foreach ($corners as $attribute => $label) {
    $form['independent_corners_set']['radii'][$attribute] = array(
      '#type' => 'textfield',
      '#title' => $label,
      '#default_value' => 0 + $action['independent_corners_set']['radii'][$attribute],
      '#size' => 2,
    );
  }

  /*
  $form['antialias'] = array(
  '#type' => 'checkbox',
  '#title' => t('antialias'),
  '#return_value' => TRUE,
  '#default_value' => $action['antialias'],
  '#description' => t('Attempt antialias smoothing when drawing the corners'),
  );
  */
  $form['notes'] = array(
    '#markup' => t('
        Note: the rounded corners effect uses true alpha transparency masking.
        This means that this effect <b>will fail to be saved</b> on jpegs
        <em>unless</em> you either <ul>
        <li>convert the image to PNG (using the coloractions filter for that),</li>
        <li>define a canvas underneath it (using canvasactions-define-canvas) or</li>
        <li>underlay a solid color (using coloractions-alpha-flatten) or</li>
        <li>underlay a background image (canvasactions-underlay)</li>
        </ul>
        as a later part of this imagecache pipeline.
        <br/>
      '),
  );
  return $form;
}