note 62106 added to function.imagefttext
| From: | php-general at lists dot php dot net | Date: | Mon, 20 Feb 2006 10:19:18 +0000 |
| Subject: | note 62106 added to function.imagefttext | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-104054@lists.php.net to get a copy of this message | ||
I am using php 5.1.2 on a winxp machine. I was getting into the TrueType fonts and wanted to see
which ones would look best incorporated into web images. So I created the following script that
prints out samples of all the TrueType fonts found in my C:\Windows\Fonts directory. The script
takes only one request parameter - 'fsize'. It stands for font-size and lets you see each
font in any size you wish -- I limited it to values between 5 and 48. Hope this helps someone other
than me :)
I apologize in advance if any of my code is not the prettiest-written php code even seen -- I have
only been coding in php for the past week (I'm a perl-guy usually).
<?php
list($x, $y, $maxwidth) = array(0, 0, 0);
$fsize = (int)$_REQUEST['fsize'];
if ($fsize < 5 or $fsize > 48) $fsize = 8;
header("Content-type: image/jpeg");
// don't know how wide or tall the font samples will be.
// create a huge image for now, we'll copy it smaller
// later when we know how large the image needs to be.
$im = imagecreate(1000, 20000) or die('could not create!');
$clr_white = imagecolorallocate($im, 255, 255, 255);
$clr_black = imagecolorallocate($im, 0, 0, 0);
$font_path = "C:/Windows/Fonts/";
$dh = opendir($font_path);
while (($file = readdir($dh)) !== FALSE) {
// we're only dealing with TTY fonts here.
if (substr(strtolower($file), -4) != '.ttf') continue;
$str = "Sample text for '$file'";
$bbox = imagettfbbox(
$fsize, 0, "{$font_path}{$file}", $str
);
$ww = $bbox[4] - $bbox[6];
$hh = $bbox[1] - $bbox[7];
imagettftext(
$im, $fsize, 0, $x, $y,
$clr_black, "{$font_path}{$file}", $str
);
$y += $hh + 20;
if ($ww > $maxwidth) $maxwidth = $ww;
}
closedir($dh);
// ok, now we can chop off the extra space from the
// 1000 x 20000 image.
$im2 = imagecreate($maxwidth + 20, $y);
imagecopyresized(
$im2, $im, 0, 0, 0, 0, $maxwidth + 20,
$y, $maxwidth + 20, $y
);
imagejpeg($im2);
imagedestroy($im);
imagedestroy($im2);
?>
----
Server IP: 66.207.199.35
Probable Submitter: 68.148.210.62
----
Manual Page -- http://www.php.net/manual/en/function.imagefttext.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+62106
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+62106&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+62106&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+62106&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+62106&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+62106&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+62106&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+62106&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+62106&report=yes
Search -- http://master.php.net/manage/user-notes.php