代码如下:
header("Content-Type: image/png");
$im=imagecreate(120,30);
$bg=imagecolorallocate($im,0,0,255);
$sg=imagecolorallocate($im,255,255,255);
imagefill($im,120,30,$bg);
imagestring($im,7,8,5,"image create",$sg);
ob_clean();
imagepng($im);
imagedestroy($im);
这个是浏览器的背景,不是生成的图片有黑幕
楼上的说的对,这是浏览器的背景,其实你要改也是可以改的,google浏览器--查看--Styles-style中的background 的颜色进行修改。
使用验证码是,在另一个页面调用可以正常显示(把你的以上php代码保存为:test_create_png.php 文件),如在以下html文件中调用test_create_png.php文件:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<img src="test_create_png.php" id="refresh" onclick="this.src='test_create_png.php?'+Math.random()">
<a href="javacript:;" onclick="document.getElementById('refresh').src='test_create_png.php?'+Math.random();">看不起,换一张</a>
</body>
</html>
显示结果如下: