You are here

function textactions_text2canvas_image in ImageCache Actions 5.3

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

Place the source image on the current background

Implementation of hook_image()

Parameters

$image:

$action:

File

./textactions.inc, line 150

Code

function textactions_text2canvas_image(&$image, $action = array()) {
  $fontpath = textactions_find_font($action['fontfile']);
  if (!$fontpath) {
    drupal_set_message(t("Failed to locate the requested font %fontfile. Cannot overlay text onto image.", array(
      '%fontfile' => $action['fontfile'],
    )));
    return FALSE;
  }
  if ($action['evaluate_text']) {
    $text = textactions_evaluate_text($image, $action);
  }
  else {
    $text = $action['text'];
  }

  // Calculate position by first creating a temp image containing the text and accessing its dimensions
  $temp = textactions_create_font_image($action['size'], $action['angle'], $fontpath, $text);
  if (!$temp) {
    drupal_set_message(t('Failed to generate text image. Cannot calculate text dimensions. Not overlaying text.'), 'error');
    return;
  }

  // parse keywords
  $x_ins = textactions_keyword_filter($action['xpos'], $image->info['width'], $temp['width'], $temp['bx'], 'x');
  $y_ins = textactions_keyword_filter($action['ypos'], $image->info['height'], $temp['height'], $temp['by'], 'y');

  // convert color from hex (as it is stored in the UI)
  if ($action['RGB']['HEX'] && ($deduced = hex_to_rgb($action['RGB']['HEX']))) {
    $action['RGB'] = array_merge($action['RGB'], $deduced);
  }
  $action['alpha'] = $action['alpha'] / 100;

  //Convert to decimal between 0 and 1
  $action['RGB']['alpha'] = (1 - $action['alpha']) * 127;

  //convert opacity to proper alpha value (0 = opaque, 127 = transparent)
  return imageapi_image_overlaytext_alpha($image, $text, $action['size'], $x_ins, $y_ins, $action['RGB'], $fontpath, $action['angle']);
}