note 33527 added to function.imagettfbbox

From: Date: Sun, 29 Jun 2003 09:39:48 +0000
Subject: note 33527 added to function.imagettfbbox
Groups: php.notes 
Request: Send a blank email to php-notes+get-51167@lists.php.net to get a copy of this message
Here is (another) approach for displaying a text in any angle inscribed in its own bounding box: <?php $font= dirname($_SERVER['DOCUMENT_ROOT']. $_SERVER['SCRIPT_NAME'])."/arial.ttf"; $ang= ($_GET['angle']? $_GET['angle']: 0) % 360; $txt= 'This is a test'; $dim= imagettfbbox(10, $ang, $font, $txt); $min_x= min($dim[0], $dim[2], $dim[4], $dim[6]); $max_x= max($dim[0], $dim[2], $dim[4], $dim[6]); $width= $max_x-$min_x+1; $min_y= min($dim[1], $dim[3], $dim[5], $dim[7]); $max_y= max($dim[1], $dim[3], $dim[5], $dim[7]); $height= $max_y-$min_y+1; $img= imagecreate($width+1, $height+1); $bgcolor= imagecolorallocate($img, 0, 0, 0); $txtcolor= imagecolorallocate($img, 255, 255, 255); imagettftext($img, 10, $ang, -$min_x+$dim[0], -$min_y+$dim[1], $txtcolor, $font, $txt); header("Content-type: image/png"); header("Content-disposition: inline; filename=text.png"); imagepng($img); imagedestroy($img); ?> If you call this script puttext.php, then would be nice to test any angle using the following script: <?php for($j=0; $j<8; $j++) { for($i=0; $i<45; $i+= 5) { echo '<IMG SRC="puttext.php?&angle='.($j*45+$i).'">'; } echo '<BR>'; } ?> You'll notice in some angles the box isn't big enough to fit the whole text. May be using floats for calculations would help, or evaluating in different ways the the angle steps 0-89, 90-179, 180-269 and 270-359. This problem occurs when displaying lower-baseline chars (y,g,j,p,q). ---- Manual Page -- http://www.php.net/manual/en/function.imagettfbbox.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33527 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33527&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33527&report=yes

« previous php.notes (#51167) next »