test.php的
<form action="index.php" method="post">
<input type="text" name="nick">
<input type="submit" name="test">
</form>
的index.php
<?php
if(isset($_POST['test'])) {
$bg = imagecreatefrompng('img/sygn/1.png') or die("t");
$font = "others/rte.ttf";
$blackColor = imagecolorallocate($bg, 47, 53, 62);
$diamondColor = imagecolorallocate($bg, 140, 244, 226);
$emeraldColor = imagecolorallocate($bg, 92, 244, 149);
$goldCollor = imagecolorallocate($bg, 234, 238, 87);
header("Content-type: image/png");
imagettftext($bg, 29, 0, 5, 33, $blackColor, $font, 'Username');
imagettftext($bg, 17, 0, 360, 83, $goldCollor, $font, '20');
imagettftext($bg, 17, 0, 360, 43, $emeraldColor, $font, '20');
imagettftext($bg, 28, 0, 50, 125, $diamondColor, $font, '400');
imagepng($bg);
imagepng($bg, "users/image.png");
imagedestroy($bg);
}
?>
我想点击按钮后显示图像。但它不起作用,我没有得到任何图像只是空白的一面。 如果我删除if语句它可以正常工作。 如果我添加:
echo '<input type="text">'
在第一行中,图像生成器也不会起作用。 例如:
include form.php
这就是我得到的:
http://screenshot.net/pjg6du1
答案 0 :(得分:0)
试试这个:
if(isset($_POST['nick']) && $_POST['nick'] != '') {
//my code
}
答案 1 :(得分:0)
答案 2 :(得分:0)
imagepng在用户目录中创建图片,但您不会在页面上显示图片。
以下正确代码:
<html>
<head>
<?php
if(isset($_POST['test'])) {
$bg = imagecreatefrompng('img/sygn/1.png') or die("t");
$font = "others/rte.ttf";
$blackColor = imagecolorallocate($bg, 47, 53, 62);
$diamondColor = imagecolorallocate($bg, 140, 244, 226);
$emeraldColor = imagecolorallocate($bg, 92, 244, 149);
$goldCollor = imagecolorallocate($bg, 234, 238, 87);
header("Content-type: image/png");
imagettftext($bg, 29, 0, 5, 33, $blackColor, $font, 'Username');
imagettftext($bg, 17, 0, 360, 83, $goldCollor, $font, '20');
imagettftext($bg, 17, 0, 360, 43, $emeraldColor, $font, '20');
imagettftext($bg, 28, 0, 50, 125, $diamondColor, $font, '400');
imagepng($bg);
imagepng($bg, "users/image.png");
imagedestroy($bg);
}
?>
</head>
<body>
<form action="test.php" method="post">
<input type="text" name="nick">
<input type="submit" name="test">
</form>
<img src="users/image.png" />
</body>
</html>