...

View Full Version : imageTTFtext spacing



jojojamm
03-08-2005, 07:31 AM
Hello!

i am use imagettftext - have tried various things, all is great!

How can I control the spacing of characters within a text?

either bring them closer together or have them spaced a bit further appart

Thanks

chump2877
03-08-2005, 08:18 AM
I've never heard of 'imagettftext', but you could use a little CSS to do that.....Look HERE (http://www.tizag.com/cssT/reference/letter-spacing.php) ....

jojojamm
03-08-2005, 08:31 AM
Thanks for the CSS example, looking for a PHP solution ...

Using imagettftext to dynamically generate text on images ... like having an email address writen on top of a image ....

http://www.php.net/manual/en/function.imagettftext.php

Scrowler
03-08-2005, 08:38 AM
chump- this is a GD lib function, which is processed at the server, so css is not applicable

Scrowler
03-08-2005, 08:40 AM
you could try adding spaces between each character like this:


<?
$string = "my string of text";
for($i=0; $i < strlen($string); $i++){
$string[$0] .= " ";
}
# string now has spaces between letters
?>

chump2877
03-08-2005, 09:50 AM
Cool, forgive my ignorance....didn't know about those functions... :p

I know this doesn't help jojo any, but what are some examples of when imagettftext (or any of the image functions) is better to use than CSS formatting and positioning...Or is it just an alternative when you are generating dynamic conent (not necessarily better or worse)?

marek_mar
03-08-2005, 04:07 PM
He tryes to position the text INSIDE an image.

jojojamm
03-08-2005, 05:05 PM
the spacing is a good idea, have tried that as well! :)

Wanting so that the user can increase/ decrease the amount of space between the characters ... making the word 'tighter' if required ....

jojojamm
03-08-2005, 06:54 PM
if this helps, this is what I have ....
managed to get the spacing, but it does not look consistent .... probably because each letter within string is a different size ...



<?php
// Set the content-type
header("Content-type: image/png");
// Create the image
$im = imagecreate(900, 900);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
// The text to draw
$Text = 'Testing1234...';
$length_string = strlen($Text);
// font file + location
$font_file = 'fonts/arial.ttf';
$Size = 12;
$font_color = $black;
$Spacing = 5;
$line = 3;
$x = 2;
$y = 20;
$a = 0;
//write string at (x,y) in black
for ($i = 1; $i <=$length_string; $i++) {
imagettftext ($im, $Size, 0, $x, $y, $font_color, $font_file, $Text{$a});
$x = $x + 8; // used for x position (spacing)
$a = $a + 1; // used for character within string
}
imagepng($im);
imagedestroy($im);

?>

Scrowler
03-08-2005, 07:03 PM
ah yes, i didn't think of that, processing each character should work fine as long as you use a monotype font

jojojamm
03-08-2005, 07:22 PM
if it was a prefect world I would stay with monotype! :D

Have to use different fonts as well ... Arial, Tahoma, Times .... etc.

Without the spacing issue, all is fine, now am requested to implement spacing .....

jdave
03-16-2005, 08:34 AM
$im = imagecreatetruecolor(300,300);
$text = "Testing Text";
$textcolor=imagecolorallocate($im,255,0,0);
$font_file = "fonts/arial.ttf";
$font_size = 10;
$spacing = 2;
$x=10;
$y=10;
for ($i = 0; $i <strlen($text); $i++)
{
$arr = imagettftext ($im, $font_size,0, $x, $y, $textcolor, $font_file, $text{$i});
$x = $arr[4]+$spacing;
}
imagejpeg($im);
destroyimage($im);



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum