2010-04-16 33 views
1

我真的有一個問題,找出如何解決這個問題。我似乎無法改變黑色的背景。這怎麼可能?字符串圖像只產生黑色背景

$string = "foo"; 
$font = 4; 
$width = ImageFontWidth($font) * strlen($string); 
$height = ImageFontHeight($font); 
$im = @imagecreatetruecolor ($width,$height); 
$bg = imagecolorallocate($im, 255, 255, 255); 
$textcolor = imagecolorallocate($im, 0, 0, 0); 
imagestring($im, 5, 0, 0, $string, $textcolor); 
imagegif($im, 'somefile.gif', 8); 
imagedestroy($im); 
+0

imagegif($ IM, 'somefile.gif',8); 可能B第二個參數需要完整路徑,這裏沒有路徑,它只有文件名......只是剔出來...... – 2010-04-16 10:27:35

回答

0

結合user279470的回答是:

$string = "foo"; 
$font = 4; 
$width = ImageFontWidth($font) * strlen($string); 
$height = ImageFontHeight($font); 
$im = @imagecreatetruecolor ($width,$height); 
$bg = imagecolorallocate($im, 255, 255, 255); 
imagefill($im, 0, 0, $bg); 
$textcolor = imagecolorallocate($im, 0, 0, 0); 
imagestring($im, 5, 0, 0, $string, $textcolor); 
imagepng($im, 'somefile.png', 8); 
imagedestroy($im);