|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[1998-07-06 06:35 UTC] ssb
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 18:00:01 2025 UTC |
It has been noted that the TTF text function is of limited use because, once you've created the text you want, there is no way to access the "bounding box" of the generated text (so you could crop your image down to size, for example). A cursory look at gdttf.c seems to show that everytime a glyph is generated and added to the final image, the function "knows" what the bounding box of the current glyph is. I don't know C, but imagine that adding some kind of tracking mechanism on a glyph by glyph basis could be used to provide the bounding box of the entire image. For example (pseudo-code): set overallbox to null; for each glyph { calculate the bounding box of the glyph -> glyphbox; generate the glyph; compare the glyphbox to the overallbox -> if (glyphbox.min_x < overallbox.min_x) { overallbox.min_x = glyphbox.min_x; } if (glyphbox.min_y < overallbox.min_y) { overallbox.min_y = glyphbox.min_y; } if (glyphbox.max_x > overallbox.max_x) { overallbox.max_x = glyphbox.max_x; } if (glyphbox.max_y > overallbox.max_y) { overallbox.max_y = glyphbox.max_y; } } Then, make the values of the overall boundingbox availble, through a PHP function like: $array = ImageTTFBoundingBox(); Anyone up for the challenge? ;)