You are here

function coloractions_alpha_form in ImageCache Actions 8

Same name and namespace in other branches
  1. 7 coloractions/transparency.inc \coloractions_alpha_form()

Image effect form callback for the alpha effect.

Parameters

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

Return value

array The form definition for this effect.

1 string reference to 'coloractions_alpha_form'
imagecache_coloractions_image_effect_info in coloractions/imagecache_coloractions.module
Implements hook_image_effect_info().

File

coloractions/transparency.inc, line 17
Helper functions for the alpha effect.

Code

function coloractions_alpha_form(array $data) {
  $defaults = array(
    'flatten' => FALSE,
    'RGB' => array(
      'HEX' => '#000000',
    ),
    'opacity' => 0.5,
  );
  $data = array_merge($defaults, (array) $data);
  $form = array();
  $form['help'] = array(
    '#markup' => t("\n      <p>You can <em>either</em> set the alpha values of the image to a fixed\n      amount by defining opacity, <em>or</em> choose a color and let the\n      darkness of the image pixels define an opacity.\n      These are different effects. Don't do both\n      or you will just get a plain block of color of a certain opacity.\n    "),
  );
  $form['opacity'] = array(
    '#type' => 'textfield',
    '#title' => t('Opacity'),
    '#default_value' => $data['opacity'],
    '#size' => 3,
    '#description' => t("\n      A decimal between 0 and 1.\n      You can define the amount of transparency to apply, eg 0.8 (80%) opacity\n      will make the image slightly transparent.\n      Use this with <em>no</em> fill color defined for normal results.\n      If you follow up by flattening the image onto white or grey,\n      this will have the effect of partial desaturation.\n    "),
  );
  $form['description'] = array(
    '#value' => t("<p>Alpha toning is an advanced method of greyscaling or colorizing.\n      It works using transparency, not colour matching.\n      The results of this filter are excellent for using as watermarks,\n      and for 'sepia' type imprints on coloured or textured backgrounds.\n      It converts dark areas of the image to opaque, light to transparent.</p>\n      <p>Note that if you are working with JPEGs, this alpha effect will not last into the final image\n      <em>unless</em> you either <strong>flatten</strong> this image against a background color\n      or image in a later process or <strong>convert</strong> it to a PNG before saving\n      using available imagecache actions.</p>"),
  );
  $form['RGB'] = imagecache_rgb_form($data['RGB']);
  $form['RGB']['#type'] = 'fieldset';
  $form['RGB']['#title'] = t('Fill Color');
  $form['RGB']['HEX']['#description'] = t("\n    Although this image will end up as an alpha transparency mask,\n    it still has to have some colour to be visible.\n    Black is safe. Dark Sepia #704214 is good too.\n    Set it to nothing to not perform any color shift.\n    ");
  $form['flatten'] = array(
    '#type' => 'checkbox',
    '#title' => t('Flatten Transparency'),
    '#default_value' => $data['flatten'],
    '#return_value' => TRUE,
    '#description' => t("The opposite of adding alpha transparency, 'flatten' will place the given colour solidly behind the image. Use this if you can't trust IE, or you really do want the image filled in with a solid colour."),
  );
  return $form;
}