How to work with imageftbbox

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
GarretD
New php-forum User
New php-forum User
Posts: 1
Joined: Wed Apr 25, 2018 7:48 pm

Wed Apr 25, 2018 8:01 pm

Hi,
I've been trying to work with imageftbbox to calculate the length of a string in pixels. Have a look at this page: https://www.baobab.nl/fonts/test.php.
In the test directory I've placed the constantia.tff file that I use to calculate the length of the string. According to imageftbbox the length of string 'How long is this string in pixels' is 442. However, when I grab the text string displayed through css and see what the length is in an image editor I get 358 pixels.
This is the code I'm using:

<style>
.kop {
background-color: #a29e25;
line-height: 30px;
font-family: Constantia;
font-size: 24px;
font-style: normal;
font-variant: normal;
color: #fff;
}
</style>
<?php
$text="How long is this string in pixels";

echo "<div class='kop'>".$text."</div>";
list($left,, $right) = imageftbbox( 24, 0, "constantia.ttf", $text);

echo $width = $right - $left;
?>

What am I doing wrong here?
Any help appreciated,
Garret

Post Reply