Anand jain Anand jain -4 years ago 131
PHP Question

how to give border to text in php gd library

How can i give border to text using PHP gd library with multicolored that is text color is different and border color is different.
As you can refer http://timage2.prepsportswear.com/GetImage.iaspx?type=1&scale=200&schoolid=3087309&p=5074&pc=forest_green&d=49784&up_pp=joe%7C78%7C1222&up_ss=hc&ver=0&r=0&ovr=1

Answer Source
// http://www.johnciacia.com/2010/01/04/using-php-and-gd-to-add-border-to-text/
 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);
}

$font_color = imagecolorallocate($im, 255, 255, 255);
$stroke_color = imagecolorallocate($im, 0, 0, 0);
imagettfstroketext($im, 60, 10, 300, 130, $font_color, $stroke_color, "wqy-  microhei.ttc", "简体繁體", 2);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download