2012-08-08 53 views
0

夥計們,我用它們的X,Y座標和給它們賦值了大約288點。我需要象徵性地表明這一點。我嘗試了gd和imagettftext,但是即使我安裝並配置了gd,繪製空白圖像的簡單代碼也無法正常工作。在PHP中繪製圖像並且不顯示任何圖像

header('Content-Type: image/png'); 

$image = imagecreatetruecolor(400, 300); 

// Allocate a color for the polygon 
$col_poly = imagecolorallocate($image, 255, 255, 255); 

// Draw the polygon 
imagepolygon($image, array(
     0, 0, 
     100, 200, 
     300, 200 
    ), 
    3, 
    $col_poly); 

// Output the picture to the browser 
header('Content-type: image/png'); 

imagepng($image); 
imagedestroy($image); 

在瀏覽器的輸出是 no image

+0

你試過了什麼? – 2012-08-08 21:54:05

+0

我試過這段代碼,並希望用值的文本填充圖像。但是一個簡單的函數不工作。可能是我的GD庫配置不正確。 – user1425322 2012-08-08 22:00:58

+0

順便說一句,爲什麼你設置標題兩次,並以不同的情況? 還要確保你的php文件中沒有空格(如果你有include,請檢查它們)。 這是一個好主意,可以讓圖像在二進制編輯器中查看。 – 2012-08-08 22:02:12

回答

0

你的代碼的工作權和圖像顯示。很可能你的GD庫沒有按預期工作。嘗試這種

$image = imagecreatetruecolor(400, 300) or die('Cannot Initialize new GD image stream'); 
+0

代碼再次顯示問題中顯示的圖像標誌?任何想法如何正確地配置GD。我已經在安裝了GD的php.ini中有extension =/conf.d/gd.so。 – user1425322 2012-08-08 21:59:25

+0

你是如何查看圖像?你是否在html圖片標籤中嘗試過它。 – 2012-08-08 22:03:24

+0

號。我該怎麼做? – user1425322 2012-08-08 22:10:05

2

嘗試與代碼中設置php文件的編碼UTF-8無BOM(例如在記事本++)。

enter image description here

+0

您可能想要考慮解釋如何使用代碼示例來執行此操作。 – 2012-11-29 18:56:16