2013-12-08 66 views
0

Helllo,使用GD我正在從$ text創建一個png圖像。 $文本是腳本生成的,可能需要幾行。 所以,這裏是我的代碼:將文本放入圖像PHP GD

$imageWidth=400; 
$imageHeight=100; 
$logoimg = imagecreatetruecolor($imageWidth, $imageHeight); //create Image 

imagealphablending($logoimg, false); 
imagesavealpha($logoimg, true); 
$col=imagecolorallocatealpha($logoimg,255,255,255,127); 
imagefill($logoimg, 0, 0, $col); 

$white = imagecolorallocate($logoimg, 0, 0, 0); 
$font = "TNR.ttf"; //font path 
$fontsize=14; 
$x=10; 
$y=20; 
$angle=0; 
imagettftext($logoimg, $fontsize,$angle , $x, $y, $white, $font, $text); 

$target="temp.png"; //path of target 
imagepng($logoimg,$target); 

我的問題是,有時文雲幾個像素裁剪。這裏有一個例子:

cropped text

所以,問題是,我怎樣才能使文本適合的形象呢?感謝您的時間!

回答