Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to give border to text in PHP GD library

Tags:

php

gdlib

How can I give border to text using PHP GD library with multicolored text, where the text color is different from the border color.

As you can refer:

enter image description here

like image 232
Anand Jain Avatar asked Nov 13 '14 09:11

Anand Jain


1 Answers

Use following function to add border to text

You can check the example output here http://wmh.github.io/hunbook/examples/gd-imagettftext.html

function imagettfstroketext(&$image, $size, $angle, $x, $y, &$textcolor, &$strokecolor, $fontfile, $text, $px) {
    for($c1 = ($x-abs($px)); $c1 <= ($x+abs($px)); $c1++)
        for($c2 = ($y-abs($px)); $c2 <= ($y+abs($px)); $c2++)
            $bg = imagettftext($image, $size, $angle, $c1, $c2, $strokecolor, $fontfile, $text);
   return imagettftext($image, $size, $angle, $x, $y, $textcolor, $fontfile, $text);
}
like image 84
Subodh Ghulaxe Avatar answered Sep 21 '22 09:09

Subodh Ghulaxe