Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    imageTTFtext spacing

    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

  • #2
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,746
    Thanks
    18
    Thanked 155 Times in 146 Posts
    I've never heard of 'imagettftext', but you could use a little CSS to do that.....Look HERE ....
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #3
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    Regular Coder
    Join Date
    Jul 2003
    Location
    New Zealand
    Posts
    435
    Thanks
    1
    Thanked 0 Times in 0 Posts
    chump- this is a GD lib function, which is processed at the server, so css is not applicable

  • #5
    Regular Coder
    Join Date
    Jul 2003
    Location
    New Zealand
    Posts
    435
    Thanks
    1
    Thanked 0 Times in 0 Posts
    you could try adding spaces between each character like this:
    PHP Code:
    <?
    $string 
    "my string of text";
    for(
    $i=0$i strlen($string); $i++){
    $string[$0] .= " ";
    }
    # string now has spaces between letters
    ?>

  • #6
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,746
    Thanks
    18
    Thanked 155 Times in 146 Posts
    Cool, forgive my ignorance....didn't know about those functions...

    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)?
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #7
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    He tryes to position the text INSIDE an image.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #8
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 ....

  • #9
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 Code:
    <?php
    // Set the content-type
    header("Content-type: image/png");
    // Create the image
    $im imagecreate(900900);
    // Create some colors
    $white imagecolorallocate($im255255255);
    $grey imagecolorallocate($im128128128);
    $black imagecolorallocate($im000);
    // 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$Size0$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);

    ?>

  • #10
    Regular Coder
    Join Date
    Jul 2003
    Location
    New Zealand
    Posts
    435
    Thanks
    1
    Thanked 0 Times in 0 Posts
    ah yes, i didn't think of that, processing each character should work fine as long as you use a monotype font

  • #11
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    if it was a prefect world I would stay with monotype!

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

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

  • #12
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Try this !!

    $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);


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •