0

I create an image dynamically using PHP GD. thus when I execute index.php it create image.png but I want image in index.php for example I can use <img src="index.php">

4

1 回答 1

4

您必须将标题内容类型设置为header('content-type: image/jpeg');
我已经为验证码实现了一次类似的代码

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);
于 2012-12-20T07:57:23.207 回答