2012-12-26 96 views
4

這是Link我正在關注創建一個圖像,但我的GD安裝並正常工作,因爲我測試了第一個示例,但此代碼中斷並標記「 圖像無法顯示,因爲它包含錯誤「。圖像無法顯示,因爲它包含錯誤在PHP gd

CODE -

<?php 
//phpinfo(); 

//Report any errors 
ini_set("display_errors", "1"); 
error_reporting(E_ALL); 

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

//Create our basic image stream 300x300 pixels 
$image = imagecreate(300, 300); 
//$image = imagecreatetruecolor(300, 300); 
//Set up some colors, use a dark gray as the background color 
$dark_grey = imagecolorallocate($image, 102, 102, 102); 
$white = imagecolorallocate($image, 255, 255, 255); 

//Set the path to our true type font 
//$font_path = 'advent_light'; 
//$font_path = 'advent_light.ttf'; 
//$font_path = 'arial'; 
$font_path = 'arial.ttf'; 

//Set our text string 
$string = 'Swapnesh!'; 

//Write our text to the existing image. 
imagettftext($image, 50, 0, 10, 160, $white, $font_path, $string); 

//Create our final image 
imagepng($image); 

//Clear up memory 
imagedestroy($image); 
?> 

事情我試圖和google搜索,但沒有解決方法如下 - :(前

  • 經過白/空格PHP的標籤,如果任何
  • 刪除標題()前的所有代碼和空格方法
  • 更改imagecreate()imagecreatetruecolor()在代碼中的註釋中。
  • 檢查font_path並根據註釋設置字體路徑。
  • 關注this & this

我的PHP版本 - PHP版本5.3.8

仍無法找到問題:(

enter image description here

錯誤

Error

EDITS -

版本1.0

這是即時得到節約什麼。

enter image description here

更多信息有關圖像 -

enter image description here

上保存頁面 - 這是文件的保存名稱 - create_png.php.png

版本1.1

<br /> 
<b>Warning</b>: imagettftext() [<a href='function.imagettftext'>function.imagettftext</a>]: Invalid font filename in <b>C:\xampp\htdocs\Core\CoreFiles\create_png.php</b> on line <b>20</b><br /> 
<br /> 
<b>Warning</b>: imagettftext() [<a href='function.imagettftext'>function.imagettftext</a>]: Invalid font filename in <b>C:\xampp\htdocs\Core\CoreFiles\create_png.php</b> on line <b>23</b><br /> 

感謝@cryptic@user1711126

解決方案 - 實際上缺少

字體文件,我們需要把我們的。文件夾下的ttf文件,以使該代碼工作或設置路徑使其工作。

回答

4

保存圖像文件的錯誤,並在文本編輯器中將其打開,如記事本或同等內容,然後查看是否有任何PHP錯誤。發生錯誤並輸出文本,然後破壞文件。這樣做,你會發現錯誤是什麼。

+0

我試過..請按照編輯..因爲它不工作:( – swapnesh

+0

@swapnesh不,將圖像保存到您的計算機硬盤驅動器,然後右鍵單擊您的硬盤驅動器上的文件,並在像記事本程序中打開它或者一些文本編輯器,然後查找會顯示PHP錯誤的文本,如果你不能這樣做,那麼請讓文件可以訪問,以便我們可以檢查文件。文件將它從create_png.php.png重新命名爲create_png.php.txt並將其打開 –

+0

@神祕的..真棒最後更有意義的東西..但仍然需要你的幫助..請按照我的新編輯:) – swapnesh

2

我嚴重懷疑你的字體路徑,請仔細檢查您的字體和文件在同一目錄下,如果是的話,改變這樣的路徑,

$font_path = './arial.ttf'; 

編輯(可根據討論中的聊天)

必須需要一個TTF文件中使用imagettftext()函數的地方ARIAL.TTF文件您的文件夾在您的文件駐留

+0

Thx for answer :)它真的幫助我們很多找出問題+1爲你的所有幫助:) – swapnesh

2

我覺得@cryptic是正確的,你需要使用的字體使用的東西,真正的路徑類似

$font_path = basename(dirname(__FILE__)).'/arial.ttf'; 

請確保字體存在於目錄中。

相關問題