Skip to content

Instantly share code, notes, and snippets.

@EugenMayer
Created August 21, 2012 07:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EugenMayer/3413173 to your computer and use it in GitHub Desktop.
Save EugenMayer/3413173 to your computer and use it in GitHub Desktop.
function calculateTextBox($text, $fontFile, $fontSize, $fontAngle) {
$boundingbox = imageTTFBbox($fontSize, $fontAngle, $fontFile, $text);
$minX = min(array($boundingbox[0], $boundingbox[2], $boundingbox[4], $boundingbox[6]));
$maxX = max(array($boundingbox[0], $boundingbox[2], $boundingbox[4], $boundingbox[6]));
$minY = min(array($boundingbox[1], $boundingbox[3], $boundingbox[5], $boundingbox[7]));
$maxY = max(array($boundingbox[1], $boundingbox[3], $boundingbox[5], $boundingbox[7]));
return array(
"left" => abs($minX) - 1,
"top" => abs($minY) - 1,
"width" => $maxX - $minX,
"height" => $maxY - $minY
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment