function _textimage_imagettfbbox in Textimage 6.2
1 call to _textimage_imagettfbbox()
- textimage_text_to_image in ./
textimage.module - Generate an image containing text with the given parameters.
File
- ./
textimage.module, line 771
Code
function _textimage_imagettfbbox($fontsize, $angle, $font, $text) {
// Get standard boundary box co-ordinates.
$coords = imagettfbbox($fontsize, 0, $font, $text);
// Get boundary box co-ordinates for firstline of text.
$firstline_coords = $coords;
if (strstr($text, "\n")) {
$lines = explode("\n", $text);
$firstline_coords = imagettfbbox($fontsize, 0, $font, $lines[0]);
}
// Get boundary box co-ordinates for baseline characters.
$baseline_coords = imagettfbbox($fontsize, 0, $font, join(drupal_map_assoc(range(33, 122), 'chr')));
// Adjust boundary box co-ordinates.
$yoffset = $firstline_coords[1] - $firstline_coords[5] >= $fontsize ? $baseline_coords[1] + 1 - $fontsize * 0.3 : 0;
$coords[0] = 0;
$coords[1] -= $yoffset;
$coords[2] = $coords[2] - $baseline_coords[6];
$coords[3] -= $yoffset;
$coords[4] = $coords[4] - $baseline_coords[0];
$coords[5] -= $yoffset;
$coords[6] = 0;
$coords[7] -= $yoffset;
// Calculate rotation variables.
$rad = deg2rad($angle);
$sin = -sin($rad);
$cos = cos($rad);
// Rotate boundary box co-ordinates.
$bbox = array();
for ($i = 0; $i < 7; $i += 2) {
$bbox[$i] = round($coords[$i] * $cos + $coords[$i + 1] * -$sin);
$bbox[$i + 1] = round($coords[$i + 1] * $cos - $coords[$i] * -$sin);
}
// Return boundary box;
return $bbox;
}