You are here

protected function TextToWrapper::drawDebugBox in Image Effects 8.2

Same name and namespace in other branches
  1. 8.3 src/Plugin/ImageToolkit/Operation/gd/TextToWrapper.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\gd\TextToWrapper::drawDebugBox()
  2. 8 src/Plugin/ImageToolkit/Operation/gd/TextToWrapper.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\gd\TextToWrapper::drawDebugBox()

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

Credit to Ruquay K Calloway.

Parameters

\Drupal\image_effects\Component\PositionedRectangle $rect: A PositionedRectangle object, including 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 TextToWrapper::drawDebugBox()
TextToWrapper::execute in src/Plugin/ImageToolkit/Operation/gd/TextToWrapper.php
Performs the actual manipulation on the image.

File

src/Plugin/ImageToolkit/Operation/gd/TextToWrapper.php, line 300

Class

TextToWrapper
Defines GD Text Overlay text-to-wrapper operation.

Namespace

Drupal\image_effects\Plugin\ImageToolkit\Operation\gd

Code

protected function drawDebugBox(PositionedRectangle $rect, $rgba, $luma = FALSE) {

  // Check color.
  if (!$rgba) {
    $rgba = '#000000FF';
  }
  elseif ($luma) {
    $rgba = ColorUtility::matchLuma($rgba);
  }

  // Retrieve points.
  $points = $this
    ->getRectangleCorners($rect);

  // Draw box.
  $data = [
    'rectangle' => $rect,
    'border_color' => $rgba,
  ];
  $this
    ->getToolkit()
    ->apply('draw_rectangle', $data);

  // Draw diagonal.
  $data = [
    'x1' => $points[0],
    'y1' => $points[1],
    'x2' => $points[4],
    'y2' => $points[5],
    'color' => $rgba,
  ];
  $this
    ->getToolkit()
    ->apply('draw_line', $data);

  // Conspicuous points.
  $orange = '#FF6400FF';
  $yellow = '#FFFF00FF';
  $green = '#00FF00FF';
  $dotsize = 6;

  // Box corners.
  for ($i = 0; $i < 8; $i += 2) {
    $col = $i < 4 ? $orange : $yellow;
    $data = [
      'cx' => $points[$i],
      'cy' => $points[$i + 1],
      'width' => $dotsize,
      'height' => $dotsize,
      'color' => $col,
    ];
    $this
      ->getToolkit()
      ->apply('draw_ellipse', $data);
  }

  // Font baseline.
  $basepoint = $rect
    ->getPoint('basepoint');
  $data = [
    'cx' => $basepoint[0],
    'cy' => $basepoint[1],
    'width' => $dotsize,
    'height' => $dotsize,
    'color' => $green,
  ];
  $this
    ->getToolkit()
    ->apply('draw_ellipse', $data);
}