You are here

function image_gd_textimage_get_bounding_box in Textimage 7.3

Return the bounding box of a text using TrueType fonts.

File

effects/textimage_text.gd.inc, line 178
GD2 toolkit for image manipulation within Textimage.

Code

function image_gd_textimage_get_bounding_box($image, $data = array()) {
  $box = new TextimageTextbox();

  // 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.
  $box
    ->set('points', imagettfbbox($data['size'], 0, $data['fontfile'], 'bdfhkltgjpqyBDFHKLTGJPQY§@çÀÈÉÌÒÇ'));
  $height = $data['lines'] * $box
    ->get('height');

  // Now get the box for full text to get width.
  $box
    ->set('points', imagettfbbox($data['size'], 0, $data['fontfile'], $data['text']));

  // Reset height.
  $box
    ->set('height', $height);

  // Rotate if angle specified.
  if ($data['angle']) {
    $box = $box
      ->getTranslatedBox($data['angle']);
  }
  return $box;
}