2014-11-14 163 views
0

我試着從現在一段時間來顯示一個用php創建的動態圖像。 我嘗試了不同的教程,他們都沒有工作。最後一次嘗試我做了這個樣子:PHP動態圖像加載

image.php

session_start(); 
$string = "bla"; 
$img = imagecreatetruecolor(80,15); 
$font_color = imagecolorallocate($img,13,28,91); 
$bg_color = imagecolorallocate($img,162,162,162); 
imagefill($img,0,0,$bg_color); 
imagestring($img, 3, 2, 0, $string, $font_color); 
header("Content-type: image/png"); 
imagepng($img); 
imagedestroy($img); 

test.php的

<html> 
    <head> 
     <meta charset="UTF-8"> 
     <title></title> 
    </head> 
    <body> 
     <?php 
     session_start(); 
     echo '<img src="image.php" />'; 
     ?> 
    </body> 
</html> 

保存圖像工作,我真的不明白什麼即時做錯了所以它加載動態。提前感謝您的任何建議。

+0

你的錯誤是什麼? – 2014-11-14 15:34:25

+0

根本沒有,如果我打電話給test.php,如果我打電話給image.php它的「圖像不能顯示,因爲它包含錯誤」,但儘可能多我已經是紅色的,它不可能在文件中顯示其創建的 – Som1 2014-11-14 15:35:59

+0

手錶對於'<?php'之前的任何空格或image.php – Florent 2014-11-14 15:36:25

回答

0

您是否擁有Apache上所有庫的權限?你也對image.php文件

session_cache_limiter('public'); 

在文件

0

在test.php的你調用session_start()一些輸出後的開始公共緩存 - html標籤。

會話無法啓動。

移動在session_start到test.php的

<?php 
session_start(); 
?> 
<html> 
.... 
some html code 

而且你不需要爲輸出img標籤使用echo頂部。你可以使用它作爲簡單的HTML。

我想你不明白如何在PHP工作會議。我建議你閱讀一些關於會議的文章。

+0

與會話問題無關,因爲 Som1 2014-11-14 16:53:36