Can gd make a border?

Discussion in 'Programming/Scripts' started by Jrdgames, Apr 15, 2007.

  1. Jrdgames

    Jrdgames New Member

    Hello,

    I am making a dynamic script in php and gd and I would like to know if there is a way to put a border on text like the stroke feature in GIMP. I looked in the phpmanual but couldn't find what i was looking for, then I tried making 2 identical texts but making one larger then the other and having it behind the other but I couldn't get it to line up properly.

    Any help would be greatly appreciated, I am using PHP 5.2.0 and GD 2.0.28 with everything.

    JRD
     
  2. petrucco

    petrucco New Member

    next add 1px border to the text. it has better look with small font size.

    ...
    // Add some shadow to the text
    imagettftext($im, 12, 0, 9, 13, $white, $font, $text);
    imagettftext($im, 12, 0, 10, 13, $white, $font, $text);
    imagettftext($im, 12, 0, 11, 13, $white, $font, $text);
    imagettftext($im, 12, 0, 9, 15, $white, $font, $text);
    imagettftext($im, 12, 0, 11, 15, $white, $font, $text);
    imagettftext($im, 12, 0, 10, 15, $white, $font, $text);
    imagettftext($im, 12, 0, 9, 14, $white, $font, $text);
    imagettftext($im, 12, 0, 11, 14, $white, $font, $text);

    // Add the text
    imagettftext($im, 12, 0, 10, 14, $black, $font, $text);
    ...
     
  3. Jrdgames

    Jrdgames New Member

    Thank you petrucco, I've tried that (like I said before) and it doesnt work how I need it too.
     
  4. mgutt

    mgutt New Member

    Last edited: Jun 3, 2009
  5. Jrdgames

    Jrdgames New Member

    Thanks mgutt that does exactly what I needed. I just wasn't able to get petrucco's code to work for me but with your function it is simple.
     
  6. mgutt

    mgutt New Member

    Yes it is simpel now, but it took me a long time to test which pixel area's need to be covered :p

    Although I don't think the results are perfect. Especially the "N", "W", etc. with hard lines seem ugly with a bold border in the corners. Maybe there is need to add some round corners with an antialiasing effect.

    P.S.: At the moment I'm working on filling fonts with a color gradient and I'm searching for a solution to have multicolored chars in a word. If you know some other effects please let me know.

    I want to generate logo's on-the-fly so every effect in combination with imagettftext is welcome.

    regards
     
  7. Jrdgames

    Jrdgames New Member

    I'm sure it did take a while, and I'm glad you were able to figure it out.

    You are correct, it could use some more fading on some of the edges, but it works fine for now. It would also be nice if it had an option of whether to give it a hard edge or not.

    If I find or develop any imagettftext functions then I'll try to remember to let you know.
     

Share This Page