You are here

function textactions_text2canvas_form in ImageCache Actions 6

Same name and namespace in other branches
  1. 5.3 textactions.inc \textactions_text2canvas_form()
  2. 5.2 textactions.inc \textactions_text2canvas_form()

Place text on top of the current canvas

Implementation of imagecache_hook_form()

Parameters

$action array of settings for this action:

Return value

a form definition

File

./textactions.inc, line 25
Helper functions for imagecache_textactions

Code

function textactions_text2canvas_form($action) {
  $defaults = array(
    'size' => 12,
    'angle' => 0,
    'xpos' => 'left+10',
    'ypos' => 'bottom-10',
    'RGB' => array(
      'red' => 51,
      'green' => 51,
      'blue' => 51,
      'HEX' => '#333333',
    ),
    'alpha' => 100,
    'fontfile' => 'liberation-fonts-1.04/LiberationSans-Regular.ttf',
    'text' => 'Hello World!',
    'evaluate_text' => FALSE,
  );
  $action = array_merge($defaults, (array) $action);
  $form = array(
    'size' => array(
      '#type' => 'textfield',
      '#title' => t('Size'),
      '#default_value' => $action['size'],
      '#description' => t('Size: The font size. Depending on your version of GD, this should be specified as the pixel size (GD1) or point size (GD2).'),
      '#size' => 3,
    ),
    'angle' => array(
      '#type' => 'textfield',
      '#title' => t('Angle'),
      '#default_value' => $action['angle'],
      '#description' => t('Angle: The angle in degrees, with 0 degrees being left-to-right reading text. Higher values represent a counter-clockwise rotation. For example, a value of 90 would result in bottom-to-top reading text.'),
      '#size' => 3,
    ),
    'alpha' => array(
      '#type' => 'textfield',
      '#title' => t('Opacity'),
      '#default_value' => $action['alpha'],
      '#size' => 3,
      '#description' => t('Opacity: 1-100.'),
      '#element_validate' => array(
        'imagecache_actions_validate_alpha',
      ),
    ),
    'xpos' => array(
      '#type' => 'textfield',
      '#title' => t('X offset'),
      '#default_value' => $action['xpos'],
      '#description' => t('Enter an offset in pixels or use a keyword: <em>left</em>, <em>center</em>, or <em>right</em>. Syntax like <em>right-20</em> is also valid.'),
      '#size' => 10,
    ),
    'ypos' => array(
      '#type' => 'textfield',
      '#title' => t('Y offset'),
      '#default_value' => $action['ypos'],
      '#description' => t('Enter an offset in pixels or use a keyword: <em>top</em>, <em>center</em>, or <em>bottom</em>. Syntax like <em>bottom-20</em> is also valid.'),
      '#size' => 10,
    ),
    'RGB' => imagecache_rgb_form($action['RGB']),
    'fontfile' => array(
      '#type' => 'textfield',
      '#title' => t('Font file name'),
      '#default_value' => $action['fontfile'],
      '#description' => t('Font file is either the full system path (eg <code>/usr/share/fonts/truetype/ttf-bitstream-vera/VeraMono.ttf</code>), a font file inside the in the module dir "%moduledir" or the files "%filedir" folder). Example: "arial.ttf". You <em>might</em> find a list of fonts available at !helplink if your system supports it.', array(
        '%moduledir' => drupal_get_path('module', 'imagecache_textactions'),
        '%filedir' => file_directory_path(),
        '!helplink' => l('fonts help', 'admin/help/imagecache_textactions'),
      )),
      '#element_validate' => array(
        'textactions_text2canvas_validate_fontfile',
      ),
    ),
    'text' => array(
      '#type' => 'textarea',
      '#rows' => 7,
      '#title' => t('Text'),
      '#default_value' => $action['text'],
      '#description' => t('The text string. If you are using a WYSIWYG editor, you should disable it for this field!'),
      '#wysiwyg' => FALSE,
    ),
    'evaluate_text' => array(
      '#type' => 'checkbox',
      '#title' => t('Evaluate text as PHP code'),
      '#default_value' => $action['evaluate_text'],
      '#description' => t('If selected, the text will be treated as PHP code.
      <p>
        Enter PHP code that will <b>return</b> your dynamic text. Do not use %php tags.
        <br />EG <code>return format_date(time());</code>
        <br /><code>return $file_data->description ? $file_data->description : $node->title;</code>
      </p>
      <p>Note that executing incorrect PHP-code can break your Drupal site.</p>
      <p>
        <b>If it\'s an image.module image</b> then a <b>$node</b> object with its values
        <em>may</em> be available.
        <br/><code>return $node->title;</code>
        <br/><code>return format_date($node->created);</code>
      </p>

      <p>
        If it\'s an image that has been attached to a node using <b>CCK-filefield-imagefield</b>
        (or just filefield)
        then as well as the parent <b>$node</b> object,
        a <b>$file_data</b> object that may contain a file description from that file field.
        <br/><code>return $file_data->description;</code>
        <small>So far that seems to be the only available \'data\' provided by filefield,
        but you can investigate the node structure using devel.module or print_r()
        to see what else this array actually contains</small>.
      </p>
      <p>
        If it\'s a file that\'s just been <b>attached using upload.module</b>,
        a <b>$file_data</b> object may also have a description.
        <br/><code>return $file_data->description;</code>
      </p>
      <p>
        If the image path is detected as belonging to more than one node, just the
        data for the first one found is returned.
      </p>

      <p>
        An "<b>$image</b>" object is also available, but that usually contains only technical data, including
        <br/><code>return $image->source;</code>
        <br/><code>return basename($image->source);</code>
        <br/><code>return $image->info["filesize"];</code>
      </p>
      ', array(
        '%php' => '<?php ?>',
      )),
    ),
  );
  if (!user_access('administer site configuration')) {
    $form['evaluate_text']['#disabled'] = TRUE;
    $form['text']['#disabled'] = $action['evaluate_text'];

    // lock this if an admin has enabled evaluation.
    $form['evaluate_text']['#description'] = 'requires <b>administer site configuration</b> permissions.';
  }
  return $form;
}