You are here

protected function TextToWrapper::getTextHeightInfo in Image Effects 8

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::getTextHeightInfo()
  2. 8.2 src/Plugin/ImageToolkit/Operation/gd/TextToWrapper.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\gd\TextToWrapper::getTextHeightInfo()

Return the height and basepoint of a text using TrueType fonts.

Need to calculate the height independently from primitive as lack of descending/ascending characters will limit the height. So to have uniformity we take a dummy string with ascending and descending characters to set to max height possible.

Parameters

string $font_size: The font size.

string $font_uri: The font URI.

Return value

array An associative array with the following keys:

  • 'height' the text height in pixels.
  • 'basepoint' an array of x, y coordinates of the font's basepoint.
1 call to TextToWrapper::getTextHeightInfo()
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 478

Class

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

Namespace

Drupal\image_effects\Plugin\ImageToolkit\Operation\gd

Code

protected function getTextHeightInfo($font_size, $font_uri) {

  // Get fully qualified font file information.
  if (!($font_file = $this
    ->getFontPath($font_uri))) {
    return NULL;
  }

  // Get the bounding box for $text to get height.
  $points = $this
    ->imagettfbboxWrapper($font_size, 0, $font_file, 'bdfhkltgjpqyBDFHKLTGJPQY§@çÅÀÈÉÌÒÇ');
  $height = abs($points[5] - $points[1]) + 1;
  return [
    'height' => $height,
    'basepoint' => [
      $points[6],
      -$points[7],
    ],
  ];
}