note 50809 added to function.imagettfbbox

From: Date: Thu, 10 Mar 2005 14:50:55 +0000
Subject: note 50809 added to function.imagettfbbox
Groups: php.notes 
Request: Send a blank email to php-notes+get-86207@lists.php.net to get a copy of this message
Here a little code snippet to align the text to horizontally center: <?php $insert = imagecreatefromgif("test.gif"); $text="TEST"; $font="arial.ttf"; //choose textcolor (black) $col=ImageColorAllocate ($insert, 0, 0, 0); //check width of the text $bbox=imagettfbbox (12, 0, $font, $text); $xcorr=0-$bbox[6]; $mase=$bbox[2]+$xcorr; //check width of the image $width=imagesx($insert); //calculate x coordinates for text $new=($width-$mase)/2; //write text imagettftext ($insert, 12, 0, $new, 50, $col, $font, $text); //output picture imagegif($insert,"",100); ?> ---- Manual Page -- http://www.php.net/manual/en/function.imagettfbbox.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+50809 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50809&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50809&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50809&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50809&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50809&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+50809&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#86207) next »