I'd really appreciate the help of anyone with more PHP experience than me.
I'm using PHP to generate close-packed text images. So far, it works like this:
- First it generates a random string of x number of characters.
- Then it makes an image with background etc.
- It places the first character in a specific place (with some randomising of the size, rotation etc)
Then it places the next character so that the bottom left corner of its bounding box is at the same point as the bottom right corner of the bounding box of the character before (plus some randomness etc). The code for that goes like this:
$coords = array(); $pos_y = $this->image_height / 2; for ($counter = 0; $counter < $this->code_length; $counter++){ $sbox = @imagettfbbox($size, $angle, $font, $this->code[$counter]); if($counter == 0) $pos_x = $this->image_width / $this->code_length; else // element 2 is the x co-ord of the bottom right corner of the ttf box $pos_x = $coords[$counter-1][2]; @imagettftext($this->image, $size, $angle, $pos_x, $pos_y, $fontcolor, $font, $this->code[$counter]); }
and repeat 4 for each subsequent character in the string.
What I want is for, as much as possible, every character to be touching its neighbour(s). What I've done so far works fine for characters like 'M' where the bottom corners of the glyph are more or less in the corners of the bounding box, but it's nowhere close for a letter like 'G' or 'I'.
Does anyone know of a way to get the actual dimensions of a ttf glyph rather than just the bounding box? Or can anyone think of any better way to approach this problem?
Any thoughts/ideas/advice much appreciated.