2013-06-29 25 views
0

我想在php中生成和顯示圖像。但我得到HTTP錯誤500:遇到意外情況.....當我打破了代碼並重試了好幾次,我發現錯誤是在我使用imagettftext的行。我的PHP版本是5.3.15和以下是我的代碼。HTTP錯誤500,而在php中使用imagettftext

$image = @imagecreate(120, 40) or die("Cannot Initialize new GD image stream"); 
$black = imagecolorallocate($image, 0, 0, 0); 
putenv('GDFONTPATH='.realpath('.')); 
$font = 'arial'; 
imagettftext($image, 20, 0, 10, 10, $black, $font , 'Print'); 

我有arial.ttf文件在php文件所在的同一目錄中。我懷疑這個錯誤是因爲php無法找到字體文件。 請提出這裏有什麼問題。

+0

你試過'$字體= 'ARIAL.TTF';'? – mb21

+1

什麼'var_dump(function_exists('imagettftext'));'輸出? –

+1

你檢查了你的錯誤日誌嗎? –

回答

0

您的php安裝中沒有TTF支持。要啓用TTF支持,PHP必須使用以下選項之一進行配置:--with-freetype-dir=DIR--with-t1lib[=DIR]--enable-gd-native-ttf

Read more about GD instalation

+0

感謝dev-null-dweller,閱讀文檔! –