On Jun 7, 7:49 pm, Rik <luiheidsgoe...@hotmail.comwrote:
On Thu, 07 Jun 2007 19:24:39 +0200, -Lost <maventheextrawo...@techie.com>
wrote:
-Lost wrote:
gbbulldog wrote:
On 6 Jun, 05:34, -Lost <maventheextrawo...@techie.comwrote:
Anyone know offhand how to center atextwithin the bounding box of an
image(width-wise at least) without the Freetype library?
>>>GD- orImageMagick-specifc code would do nicely.
>1. Determine the width of theimage.
2. Determine the width of thetext, (I'm assuming you'll be outputting
textusing TTF?), using imagettfbbox()
3. The left-hand position of thetextshould be : (image'swidth / 2)
- (textwidth / 2)
Thanks!
Ooops! I have no clue why I said thanks.
I specifically said "without the Freetype library."
That function depends on its functionality to work as expected.
Write your own variant of the freetypre library if it isn't available,
that's the only solution. There's no other way you can know the width of
dynamictextwith an arbitrary font. Yes, it's a pain, so if the library
isn't available seriously consider changing hosts and/or change the server.
--
Rik Wasmus
function getTextPosition($text,$center)
{
$im_tmp = imagecreatetruecolor(500,500);
$point_array = imagettftext($im_tmp,
20,0,0,50,imagecolorallocate($im0,0,0),'C:\Windows \Fonts\Verdana.ttf',
$text);
imagedestroy($im_tmp);
$left_x = $point_array[0];
$right_x = $point_array[2];
$length = $right_x - $left_x;
$text_position = $center - ($length/2);
return $text_position;
}
Sorry about the poor coding but this ought to take care of it. The
function will return the x coordinate that your text should be placed
at to be centered on $center. Just adjust the imagettftext function
to use your own font and size. All it does within the function is
place that text on a dummy image and read the points off of it. Let
me know if this works.
Eric