note 33527 deleted from function.imagettfbbox by sniper

From: Date: Fri, 07 Nov 2003 12:41:39 +0000
Subject: note 33527 deleted from function.imagettfbbox by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-60083@lists.php.net to get a copy of this message
Note Submitter: dinko@dinko.cl ---- 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).

« previous php.notes (#60083) next »