2012-07-28 7 views
4

모든 것이이 이미지의 텍스트를 회전하고 가운데 맞추기 위해 작동하지만 imagecolortransparent 함수로 만든 텍스트 주위에 검은 색 테두리가 있습니다. 텍스트와 배경이 투명한 이미지를 만들려면 어떻게해야합니까?GD를 사용하여 텍스트와 투명한 배경으로 이미지 만들기 PHP

header('Content-Type: image/png'); 

$title = "test text"; 

$im = imagecreatetruecolor(87, 80); 
$white = imagecolorallocate($im, 255, 255, 255); 
$black = imagecolorallocate($im, 0, 0, 0); 
imagefill($im, 87, 80, $black); 
imagecolortransparent($im, $black); 

$white = imagecolorallocate($im, 255, 255, 255); 
$font = "../fonts/arial.ttf"; 

$bbox = imagettfbbox(12,-40,"../fonts/arial.ttf", $title); 
$width = $bbox[2]-$bbox[0]; 
$height = ceil(($bbox[6]-$bbox[0])/2); 

$pos = ceil((87-$width)/2); 
$posx = $pos-$height; 
$posy = $pos+$height; 

imagettftext($im, 12, -45, $posx, $posy, $white, $font, $title); 

imagepng($im); 
imagedestroy($im); 

답변

3

당신이 원하는 것은 색상이이를 수행에 대한 부정적인를 사용하여, 앤티 앨리어싱을 해제하는 것입니다 : 여기에 코드입니다.

imagettftext($im, 12, -45, $posx, $posy, -$white, $font, $title); 
관련 문제