사이트 내 전체검색
PHP
PHP에서 GD 라이브러리를 활용하여 그림에 텍스트를 추가하고 텍스트에 윤곽선을 넣는 방법
하우코드
https://cmd.kr/php/976 URL이 복사되었습니다.

본문

 

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



//$arr2[4]='홍길동';

//$arr2[4]='홍길동';

$fontwidth = imagefontwidth($font);

$size=$arr2[3];

$text=$arr2[4];

$center = ($fontwidth*(strlen($text)/2));

$bbox = imagettfbbox($arr2[3], 0, $fontname, $text);

$center1 = intval(($bbox[2] - $bbox[0]) / 2);

$center_width=intval($arr2[5]*$fontwidth);

$angle=0;

$x=intval($arr2[0]+$center_width-$center1);

$y=intval($arr2[1]);

$stroke_color = imagecolorallocate($im, 0, 0, 0);

$stroke_px=2;

//ImageTTFtext($im, $arr2[3], $angle=0, intval($arr2[0]+$center_width-$center1), intval($arr2[1]), $ch_color,$fontname, $arr2[4]);

imagettfstroketext($im, $size, $angle, $x, $y, $ch_color, $stroke_color, $fontname, $text, $stroke_px);


댓글목록

등록된 댓글이 없습니다.

PHP
871 (1/18P)

Search

Copyright © Cmd 명령어 3.238.121.7