You are here

function _textimage_draw_debug_box in Textimage 7.3

Display a polygon enclosing the text line, and conspicuous points.

Credit to Ruquay K Calloway

Parameters

object $image: Image object.

TextimageTextbox $box: Textbox object to draw (inclusing basepoint).

string $rgba: RGBA color of the rectangle.

bool $luma: if TRUE, convert RGBA to best match using luma.

See also

http://ruquay.com/sandbox/imagettf

1 call to _textimage_draw_debug_box()
image_gd_textimage_text_to_image in effects/textimage_text.gd.inc
Creates a new image resource and overlays the text over it.

File

effects/textimage_text.inc, line 1454
Implementation of the 'textimage_text' image effect.

Code

function _textimage_draw_debug_box($image, TextimageTextbox $box, $rgba, $luma = FALSE) {

  // Check color.
  if (!$rgba) {
    $rgba = '#00000000';
  }
  elseif ($luma) {
    $rgba = textimage_match_luma($rgba);
  }

  // Retrieve points.
  $points = $box
    ->get('points');

  // Draw box.
  _textimage_draw_box($image, $points, $rgba);

  // Draw diagonal.
  $data = array(
    'a' => array(
      $points[0],
      $points[1],
    ),
    'b' => array(
      $points[4],
      $points[5],
    ),
    'rgba' => $rgba,
  );
  image_toolkit_invoke('textimage_draw_line', $image, array(
    $data,
  ));

  // Conspicuous points.
  $orange = '#FF640000';
  $yellow = '#FFFF0000';
  $green = '#00FF0000';
  $dotsize = 6;

  // Box corners.
  for ($i = 0; $i < 8; $i += 2) {
    $col = $i < 4 ? $orange : $yellow;
    $data = array(
      'c' => array(
        $points[$i],
        $points[$i + 1],
      ),
      'width' => $dotsize,
      'height' => $dotsize,
      'rgba' => $col,
    );
    image_toolkit_invoke('textimage_draw_ellipse', $image, array(
      $data,
    ));
  }

  // Font baseline.
  $data = array(
    'c' => $box
      ->get('basepoint'),
    'width' => $dotsize,
    'height' => $dotsize,
    'rgba' => $green,
  );
  image_toolkit_invoke('textimage_draw_ellipse', $image, array(
    $data,
  ));
}