2014-11-04 56 views
0

我試試這個代碼imagettftext()imagettftext不工作

// Set the content-type 
header('Content-Type: image/png'); 

// Create the image 
$im = imagecreatetruecolor(400, 30); 

// Create some colors 
$white = imagecolorallocate($im, 255, 255, 255); 
$grey = imagecolorallocate($im, 128, 128, 128); 
$black = imagecolorallocate($im, 0, 0, 0); 
imagefilledrectangle($im, 0, 0, 399, 29, $white); 

// The text to draw 
$text = 'Testing...'; 
// Replace path by your own font path 
$font = 'arial.ttf'; 

// Add the text 
imagettftext($im, 20, 0, 10, 20, $black, $font, $text); 

// Using imagepng() results in clearer text compared with imagejpeg() 
imagepng($im); 
imagedestroy($im); 

但它不工作,因爲它應該,我有GD和FreeType的安裝,你可以看到: enter image description here

誰都可以指着我正確的方向?

+0

你好,顯示的錯誤是什麼? (要查看它,請在刪除內容類型標題後直接訪問您的圖像)。 – 2014-11-04 18:35:39

回答

0

將變量$ font分配給字體文件的絕對路徑。

+0

更改爲絕對路徑,仍然是同樣的問題:( – TorrBallen 2014-11-04 11:27:29

+0

您包括代碼中的任何文件? – unknown007 2014-11-04 12:50:20

+0

Nop,我在主帖中粘貼的代碼是我嘗試運行的唯一代碼 – TorrBallen 2014-11-04 12:57:25

0
// Replace path by your own font path 
$font = 'arial.ttf'; 

您的代碼正在尋找不存在的「arial.ttf」。請將字體文件(arial.ttf)複製到代碼的相同目錄中。

+0

它與代碼位於同一個目錄中。 – TorrBallen 2014-11-04 11:23:57