note 75062 added to function.imagettftext

From: Date: Thu, 10 May 2007 13:56:30 +0000
Subject: note 75062 added to function.imagettftext
Groups: php.notes 
Request: Send a blank email to php-notes+get-126388@lists.php.net to get a copy of this message
Roy van Arem suggested a neat code for listing TTFs on a machine. However, it has some problems (such as lower and upper case distinction of file extension and defective fonts) that I have corrected in the following script, which can be implemented as a single PHP script (name as you like): <?php //make sure there are no blank lines above $ffolder="/usr/local/bin/fonts"; //The directory where your fonts reside if (empty($_GET['f'])) { $folder=dir($ffolder); //open directory echo "<HTML><BODY>\n"; while($font=$folder->read()) if(stristr($font,'.ttf')) //only ttf fonts $fonts[]=$font; $folder->close(); if (!empty($fonts)) { echo "<table><tr><th colspan='2'>Fonts available in $ffolder</th></tr>" ."\n<tr><th>Name</th><th>Appereance</th>"; sort($fonts); foreach ($fonts as $font) echo "<tr><td>$font</td><td> <IMG src='".$_SERVER['SCRIPT_NAME'] ."?f=$font'></td></tr>\n"; } else echo "No fonts found from $ffolder"; echo "\n</HTML></BODY>"; } else { $im=@imagecreatetruecolor(200,30) or die("Cannot Initialize new GD image stream"); $black=imagecolorallocate($im,0,0,0); $white=imagecolorallocate($im,255,255,255); imagefill($im,0,0,$white); imagettftext($im,14,0,5,25,$black, "$ffolder/".$_GET['f'] , $_GET['f']); header("Content-type: image/png"); header('Content-Length: ' . strlen($im)); imagepng($im); imagedestroy($im); } ?> ---- Server IP: 62.237.7.3 Probable Submitter: 128.214.215.13 ---- Manual Page -- http://www.php.net/manual/en/function.imagettftext.php Edit -- https://master.php.net/note/edit/75062 Del: integrated -- https://master.php.net/note/delete/75062/integrated Del: useless -- https://master.php.net/note/delete/75062/useless Del: bad code -- https://master.php.net/note/delete/75062/bad+code Del: spam -- https://master.php.net/note/delete/75062/spam Del: non-english -- https://master.php.net/note/delete/75062/non-english Del: in docs -- https://master.php.net/note/delete/75062/in+docs Del: other reasons-- https://master.php.net/note/delete/75062 Reject -- https://master.php.net/note/reject/75062 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#126388) next »