我尝试通过PHP GD来制作Captcha。但是不幸的是我遇到了一个问题!PHP告诉我:
The image “http://127.0.0.1/par.php” cannot be displayed because it contains errors.
Run Code Online (Sandbox Code Playgroud)
我的代码是这样
<?php
header ('Content-Type: image/png');
$im = @imagecreatetruecolor(120, 20)
or die('Cannot Initialize new GD image stream');
$text_color = imagecolorallocate($im, 233, 14, 91);
$red = imagecolorallocate($im, 255, 0, 0);
for ($i=0;i<=120;$i=$i+1){
for ($j=0;$j<=20;$j=$j+1){
imagesetpixel($im, $i,$j,$red);
}
}
imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color);
imagepng($im);
imagedestroy($im);
?>
Run Code Online (Sandbox Code Playgroud)
$im = @imagecreatetruecolor(120, 20)
or die('Cannot Initialize new GD image stream');
Run Code Online (Sandbox Code Playgroud)
您首先隐藏真正的错误,然后尝试显示某些内容...
您不会查找而无法显示的内容,
并公开图像,无论它是否真正生成。
然后您继续进行stackoverflow,并希望有人可以猜测您可能只是使用@
operator 抑制的错误。
确保之前没有任何东西<?php
,如果有的话,请最后删除?>
。
为确保已安装GD,请在新的php文件中尝试以下操作:
<?php
if (extension_loaded('gd') && function_exists('gd_info')) {
echo "PHP GD library is installed on your web server";
}
else {
echo "PHP GD library is NOT installed on your web server";
}
Run Code Online (Sandbox Code Playgroud)