kerning and freetype

heya,

i have an on the fly image to png converter in php. My issue is that as far as i have seen, there is no availablility for one to 'kern' or space letters. As a result i get certain letters , i.e EZ which link, and i need spacing put on such instances.

i am using GD and freetype, and also am using a true type font.
the relevant function calls are:

ImageTTFText and
ImageTTFBBox

tia

-twans
twansAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Diablo84Commented:
hi twans,

I left this question awhile to see if any ideas would come up better then what i had in mind.

The following works like so, you call the function and specify a padding amount (amount of space between each letter in pixels) as well as various other paramaters present in ImageTTFText.

The function then breaks the string up into an array and loops through each item (letter) and output that letter in the correct place. The placement is calculated each time based on the starting X position, the pixel space the last character took up and the padding specified when the function was called.

It may need some tweaking to perfect but should demonstrate a method of achieving this:

_____________________________________________________________________

<?php
function imagekerntext($im,$size,$x,$x_pad,$y,$col,$font,$text) {
 $letters = preg_split('//',$text,-1,PREG_SPLIT_NO_EMPTY);
 foreach ($letters as $var) {
  $char_width = imagettfbbox($size,0,$font,$var);
  imagettftext($im,$size,0,$x,$y,$col,$font,$var);
  $x = $x + ($char_width[2] - $char_width[0]) + $x_pad;
 }
}

$im = imagecreate(250,50);

$bg = imagecolorallocate($im,200,200,200);
$col = imagecolorallocate($im,0,0,0);

$text = "abcdefghijklmnopqrstuvwxyz";
$font = "arial.ttf";

//parameters: image, font size, starting x, paddng x, y, colour, font, text
imagekerntext($im,12,5,2,15,$col,$font,$text);

header("Content-type: image/jpeg");
imagejpeg($im);

imagedestroy($im);
?>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
twansAuthor Commented:
diablo,
 
thanks very much, it was exactly what i was after. appreciate it :)

-twans
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.