note 11807 added to function.imagettfbbox.php

From: Date: Thu, 08 Mar 2001 04:26:07 +0000
Subject: note 11807 added to function.imagettfbbox.php
Groups: php.notes 
Request: Send a blank email to php-notes+get-12023@lists.php.net to get a copy of this message
Here is some code I've used to create an image with text centered left to right. I have still yet to figure out how to get it centered top to bottom. If anyone can figure out how to get a pixel height on a text box, please post. <?php $imagewidth = 100; $imageheight = 20; $fontsize = 12; $myimg=ImageCreate($imagewidth, $imageheight); $col1=ImageColorAllocate($myimg, 255, 0, 0); $col2=ImageColorAllocate($myimg, 255, 255, 255); $thetextbox = ImageTTFBBox ($fontsize, 0, "./ttfonts/arialnb.ttf", "My Button"); $textwidth = (($thetextbox[4] + $thetextbox[2]) / 2) - (($thetextbox[6] + $thetextbox[0]) / 2); $xpos = ($imagewidth - $textwidth) / 2; $ypos = 14; ImageTTFText ($myimg, $fontsize, 0, $xpos, $ypos, $col2, "./ttfonts/arialnb.ttf", "My Button"); ImagePNG($myimg, "myimg.png"); ImageDestroy($myimg); ?> <img src="myimg.png" border=0> http://www.php.net/manual/en/function.imagettfbbox.php

« previous php.notes (#12023) next »