You are here

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

Return the width of a text using TrueType fonts.

Parameters

string $text: A text string.

string $font_size: The font size.

string $font_uri: The font URI.

Return value

int The width of the text in pixels.

2 calls to TextToWrapper::getTextWidth()
TextToWrapper::execute in src/Plugin/ImageToolkit/Operation/gd/TextToWrapper.php
Performs the actual manipulation on the image.
TextToWrapper::wrapText in src/Plugin/ImageToolkit/Operation/gd/TextToWrapper.php
Wrap text for rendering at a given width.

File

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

Class

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

Namespace

Drupal\image_effects\Plugin\ImageToolkit\Operation\gd

Code

protected function getTextWidth($text, $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 width.
  $points = $this
    ->imagettfbboxWrapper($font_size, 0, $font_file, $text);

  // Return bounding box width.
  return abs($points[4] - $points[6]) + 1;
}