You are here

function canvasactions_perspective_form in ImageCache Actions 7

Image effect form callback for the Perspective effect.

Parameters

array $data: The current configuration for this image effect.

Return value

array The form definition for this effect.

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

File

canvasactions/canvasactions.inc, line 1266

Code

function canvasactions_perspective_form(array $data) {
  $defaults = array(
    'vanish' => 'right',
    'symmetry' => 'symmetrical',
    'distortion' => 14,
    'opposite_distortion' => 10,
  );
  $data = array_merge($defaults, $data);
  $form['vanish'] = array(
    '#type' => 'radios',
    '#title' => t('Vanishing point'),
    '#options' => array(
      'top' => t('Top'),
      'left' => t('Left'),
      'right' => t('Right'),
      'bottom' => t('Bottom'),
    ),
    '#theme' => 'canvasactions_perspective_anchor',
    '#default_value' => $data['vanish'],
    '#description' => t('The position of the vanishing point relative to the source image.'),
  );
  $form['symmetry'] = array(
    '#type' => 'radios',
    '#title' => t('Symmetry of image perspective'),
    '#description' => t('If symmetrical, the perspective effect will be built symmetrically. If asymmetrical, you can set different distortion values for both sides. Mathematically speaking: symmetrical distortion results in an isosceles trapezoid, whereas asymmetrical distortion results in just an acute trapezoid.'),
    '#default_value' => $data['symmetry'],
    '#options' => array(
      'symmetrical' => t('Symmetrical perspective'),
      'asymmetrical' => t('Asymmetrical perspective'),
    ),
  );
  $form['distortion'] = array(
    '#type' => 'textfield',
    '#title' => t('Distortion'),
    '#field_suffix' => '%',
    '#size' => 5,
    '#default_value' => $data['distortion'],
    '#element_validate' => array(
      'canvasactions_perspective_distortion_validate',
    ),
    '#description' => t('How much the corner(s) (on the vanishing point side of the image) should move to the horizon (i.e. the line containing the vanishing point). With 0% you will have no perspective effect at all and the vanishing point will be infinitely far away. With a sum of 100%, the 2 corner(s) and the vanishing point will be the same, resulting in a triangle instead of a trapezoid. For a pleasing effect, you should choose (a) number(s) between 0 and 35%, especially with ImageMagick as that toolkit also adds some stretching within the image.'),
  );
  $form['opposite_distortion'] = array(
    '#type' => 'textfield',
    '#title' => t('Distortion for opposite side'),
    '#states' => array(
      'visible' => array(
        ':input[name="data[symmetry]"]' => array(
          'value' => 'asymmetrical',
        ),
      ),
    ),
    '#field_suffix' => '%',
    '#size' => 5,
    '#default_value' => $data['opposite_distortion'],
    '#element_validate' => array(
      'canvasactions_perspective_distortion_validate',
    ),
    '#description' => t('How much the 2nd corner on the vanishing point side of the image should move to the horizon line containing the vanishing point.'),
  );
  $form['additional_help'] = array(
    '#markup' => '<p>Some notes:</p>
      <ul><li>This effect adds a perspective effect to an image.
      Normally, to get a realistic effect, the side that gets the perspective effect should be reduced in size.
      However, this effect does not do so, as it is easy to add a (percentage) resize effect to the image style yourself.
      A resize to 85% of the original size is a good start when experimenting.</li>
      <li>CSS3 also defines <a href="https://www.w3.org/TR/2009/WD-css3-3d-transforms-20090320/#perspective-property">3D perspective transformations</a>.
      So you might get some of the results of ths effect with pure CSS as well.</li></ul>',
  );
  return $form;
}