2012-12-20 59 views
-2

我使用PHP GD動態創建圖像。因此,當我執行的index.php它創建image.png但我想的index.php例如圖像,我可以使用<img src="index.php">動態創建圖像 - PHP GD

+0

http://stackoverflow.com/questions/2010742/image-processing-and-output-using-gd-in-php – ke20

回答

4

你必須設置頁眉內容類型header('content-type: image/jpeg');
我已經爲實現類似的代碼,一旦captcha

header("Content-type: image/png"); 
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past 
$string = "Type Me"; 
$im  = imagecreatefrompng(IMAGEDIR."captcha.png"); 
$orange = imagecolorallocate($im, 0, 0, 0); 
$px  = (imagesx($im) - 7.5 * strlen($string))/2; 
imagestring($im, 5, $px, 9, $string, $orange); 
imagepng($im); 
imagedestroy($im);