note 45518 added to function.imagettftext
| From: | webmaster at funkysigs dot co dot uk | Date: | Thu, 09 Sep 2004 15:16:06 +0000 |
| Subject: | note 45518 added to function.imagettftext | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-76331@lists.php.net to get a copy of this message | ||
In reply to chmouel@chmouel.com
The method I am using for calculating the average font character size is as follows:
<?php
//This will work out the font spacing for the given font and font size.
$font = "fonts/arial.ttf";
$fontsize = 12;
$test = "abcdefghijklmnopqrstuvwxyz";
$bbox = imagettfbbox($fontsize, 0, $font, $test);
$testwidth = max($bbox[0],$bbox[2],$bbox[4],$bbox[6]) - min($bbox[0],$bbox[2],$bbox[4],$bbox[6]);
//Take off 28 (total no. of pixels used as gaps between the 26 characters)
$font_space = ($testwidth - 28 ) / 26;
?>
I am currently using this on various fonts between size 8 and size 12.. The more characters you
include in the test string the more accurate the font spacing should be. I find the majority are
lowercase alpha characters on my site so this works fine for me.
----
Manual Page -- http://www.php.net/manual/en/function.imagettftext.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+45518
Delete -- http://master.php.net/manage/user-notes.php?action=delete+45518&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+45518&report=yes
Search -- http://master.php.net/manage/user-notes.php