note 45518 deleted from function.imagettftext by aidan
| From: | aidan@php.net | Date: | Mon, 20 Sep 2004 08:46:41 +0000 |
| Subject: | note 45518 deleted from function.imagettftext by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-77006@lists.php.net to get a copy of this message | ||
Note Submitter: webmaster at funkysigs dot co dot uk
----
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.