You are here

function textimage_preset_edit in Textimage 5

Same name and namespace in other branches
  1. 5.2 textimage_admin.inc \textimage_preset_edit()
  2. 6.2 textimage_admin.inc \textimage_preset_edit()
  3. 7.2 textimage.admin.inc \textimage_preset_edit()
1 string reference to 'textimage_preset_edit'
textimage_menu in ./textimage.module
Implementation of hook_menu().

File

./textimage.module, line 281

Code

function textimage_preset_edit($preset_id) {
  if (is_numeric($preset_id)) {
    $preset = _textimage_preset_load($preset_id);
  }
  else {
    $preset = array();
  }
  $fonts_path = variable_get('textimage_fonts_path', '');
  $font_options = drupal_map_assoc(_textimage_font_list($fonts_path));
  $images_path = variable_get('textimage_images_path', '');
  $image_files = drupal_map_assoc(_textimage_image_list($images_path));
  $image_presets = array();
  $presets = textimage_get_presets();
  foreach ($presets as $p) {
    if ($p['pid'] != $preset_id) {
      $image_presets[$p['pid']] = $p['name'];
    }
  }
  $image_options = array(
    t('Default:') => array(
      '' => t('Default (use background color)'),
    ),
    t('Use the result of Text Image Preset:') => $image_presets,
    t('Use a Background Image:') => $image_files,
  );
  $form = array();
  $form['#tree'] = TRUE;
  $form['preset_id'] = array(
    '#type' => 'value',
    '#value' => $preset_id,
  );
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Preset Name'),
    '#description' => t('Preset names should be short and only use alphanumeric characters. This name will be used in the image path for all generated images.'),
    '#default_value' => $preset['name'],
    '#required' => TRUE,
  );
  $form['settings']['description'] = array(
    '#type' => 'textarea',
    '#title' => t('Description'),
    '#description' => t('A short description displayed in the list of presets.'),
    '#default_value' => $preset['settings']['description'],
    '#rows' => 1,
  );
  $form['settings']['text'] = array(
    '#type' => 'fieldset',
    '#title' => t('Text Settings'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['settings']['text']['font'] = array(
    '#type' => 'select',
    '#title' => t('Font'),
    '#options' => $font_options,
    '#default_value' => $preset['settings']['text']['font'],
    '#description' => t('Select the font to be used in this image. If no fonts are listed, check the <a href="!path">settings for TrueType Fonts Path</a>.', array(
      '!path' => url('admin/settings/textimage'),
    )),
    '#required' => TRUE,
  );
  $form['settings']['text']['size'] = array(
    '#type' => 'textfield',
    '#title' => t('Font Size'),
    '#description' => t('Enter the size in pixels of the text to be generated.'),
    '#default_value' => $preset['settings']['text']['size'] ? $preset['settings']['text']['size'] : 16,
    '#maxlength' => 4,
    '#size' => 4,
    '#required' => TRUE,
    '#validate' => array(
      '_textimage_number_validate' => array(
        'size',
      ),
    ),
  );
  $form['settings']['text']['color'] = array(
    '#type' => 'textfield',
    '#title' => t('Text Color'),
    '#description' => t('Enter the hex color code you wish to use for the generated text (i.e. #000000).'),
    '#default_value' => $preset['settings']['text']['color'],
    '#maxlength' => 7,
    '#size' => 7,
    '#validate' => array(
      '_textimage_hex_validate' => array(
        'color',
      ),
    ),
    '#required' => TRUE,
  );
  $form['settings']['text']['maximum_width'] = array(
    '#type' => 'textfield',
    '#title' => t('Maximum width'),
    '#field_suffix' => t('pixels'),
    '#description' => t('Text lines wider than this will be wrapped. Leave blank to disable wrapping.'),
    '#default_value' => $preset['settings']['text']['maximum_width'],
    '#maxlength' => 4,
    '#size' => 4,
  );
  $form['settings']['text']['fixed_width'] = array(
    '#type' => 'checkbox',
    '#title' => t('Fixed width?'),
    '#description' => t('If checked the size of generated image will always be equal to the max width.'),
    '#default_value' => $preset['settings']['text']['fixed_width'],
  );
  $form['settings']['text']['align'] = array(
    '#type' => 'select',
    '#title' => t('Text Align'),
    '#description' => t('Only works when fixed width is enabled.'),
    '#options' => array(
      ALIGN_LEFT => t('Left'),
      ALIGN_CENTER => t('Center'),
      ALIGN_RIGHT => t('Right'),
    ),
    '#default_value' => $preset['settings']['text']['align'],
  );
  $form['settings']['text']['angle'] = array(
    '#type' => 'textfield',
    '#title' => t('Text Rotation'),
    '#description' => t('Enter the angle in degrees at which the text will be displayed. Positive numbers rotate the text clockwise, negative numbers counter-clockwise.'),
    '#default_value' => $preset['settings']['text']['angle'] ? $preset['settings']['text']['angle'] : 0,
    '#maxlength' => 4,
    '#size' => 4,
    '#validate' => array(
      '_textimage_number_validate' => array(
        'angle',
      ),
    ),
  );
  $form['settings']['text']['case'] = array(
    '#type' => 'radios',
    '#title' => t('Convert to case'),
    '#options' => array(
      '' => t('Default'),
      'upper' => t('UPPERCASE'),
      'lower' => t('lowercase'),
      'ucwords' => t('Uppercase Words'),
      'ucfirst' => t('Uppercase first'),
    ),
    '#description' => t('Covert the input text to a consistent format. The default makes no changes to input text.'),
    '#default_value' => $preset['settings']['text']['case'],
  );
  $form['settings']['text']['stroke_width'] = array(
    '#type' => 'textfield',
    '#title' => t('Outline Width'),
    '#description' => t('Optionally add a stroke outline around the text. Enter the stroke width in pixels.'),
    '#default_value' => $preset['settings']['text']['stroke_width'],
    '#maxlength' => 1,
    '#size' => 4,
    '#validate' => array(
      '_textimage_number_validate' => array(
        'stroke_width',
      ),
    ),
  );
  $form['settings']['text']['stroke_color'] = array(
    '#type' => 'textfield',
    '#title' => t('Outline Color'),
    '#description' => t('Enter the hex color code you wish to use for the stroke outline (i.e. #000000).'),
    '#default_value' => $preset['settings']['text']['stroke_color'],
    '#maxlength' => 7,
    '#size' => 7,
    '#validate' => array(
      '_textimage_hex_validate' => array(
        'color',
      ),
    ),
  );
  $form['settings']['text']['margin_top'] = array(
    '#type' => 'textfield',
    '#title' => t('Text Margin Top'),
    '#default_value' => $preset['settings']['text']['margin_top'] ? $preset['settings']['text']['margin_top'] : 0,
    '#maxlength' => 4,
    '#size' => 4,
    '#validate' => array(
      '_textimage_number_validate' => array(
        'margin_top',
      ),
    ),
  );
  $form['settings']['text']['margin_right'] = array(
    '#type' => 'textfield',
    '#title' => t('Text Margin Right'),
    '#default_value' => $preset['settings']['text']['margin_right'] ? $preset['settings']['text']['margin_right'] : 0,
    '#maxlength' => 4,
    '#size' => 4,
    '#validate' => array(
      '_textimage_number_validate' => array(
        'margin_top',
      ),
    ),
  );
  $form['settings']['text']['margin_bottom'] = array(
    '#type' => 'textfield',
    '#title' => t('Text Margin Bottom'),
    '#default_value' => $preset['settings']['text']['margin_bottom'] ? $preset['settings']['text']['margin_bottom'] : 0,
    '#maxlength' => 4,
    '#size' => 4,
    '#validate' => array(
      '_textimage_number_validate' => array(
        'margin_bottom',
      ),
    ),
  );
  $form['settings']['text']['margin_left'] = array(
    '#type' => 'textfield',
    '#title' => t('Text Margin Left'),
    '#description' => t('Specify the margin in pixels to be added around the generated text.'),
    '#default_value' => $preset['settings']['text']['margin_left'] ? $preset['settings']['text']['margin_left'] : 0,
    '#maxlength' => 4,
    '#size' => 4,
    '#validate' => array(
      '_textimage_number_validate' => array(
        'margin_left',
      ),
    ),
  );
  $form['settings']['background'] = array(
    '#type' => 'fieldset',
    '#title' => t('Background'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['settings']['background']['color'] = array(
    '#type' => 'textfield',
    '#title' => t('Background Color'),
    '#description' => t('Enter the hex color code you wish to use for the background of the generated image (i.e. #FFFFFF). Leave blank for transparent.'),
    '#default_value' => $preset['settings']['background']['color'],
    '#maxlength' => 7,
    '#size' => 7,
    '#validate' => array(
      '_textimage_hex_validate' => array(
        'color',
      ),
    ),
  );
  $form['settings']['background']['image'] = array(
    '#type' => 'select',
    '#title' => t('Background Image'),
    '#options' => $image_options,
    '#default_value' => $preset['settings']['background']['image'],
    '#description' => t('Select the font to be used in this image. If no fonts are listed, check the <a href="!path">settings for TrueType Fonts Path</a>.', array(
      '!path' => url('admin/settings/textimage'),
    )),
  );
  $form['settings']['background']['xoffset'] = array(
    '#type' => 'textfield',
    '#title' => t('Text X-Offset'),
    '#default_value' => $preset['settings']['background']['xoffset'] ? $preset['settings']['background']['xoffset'] : 0,
    '#maxlength' => 4,
    '#size' => 4,
    '#validate' => array(
      '_textimage_number_validate' => array(
        'xoffset',
      ),
    ),
  );
  $form['settings']['background']['yoffset'] = array(
    '#type' => 'textfield',
    '#title' => t('Text Y-Offset'),
    '#description' => t('Specify the x and y coordinates on the image you where the top-left corner of the dynamic text should be positioned.'),
    '#default_value' => $preset['settings']['background']['yoffset'] ? $preset['settings']['background']['yoffset'] : 0,
    '#maxlength' => 4,
    '#size' => 4,
    '#validate' => array(
      '_textimage_number_validate' => array(
        'yoffset',
      ),
    ),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
  );
  return $form;
}