PHP imagettfext 不显示工作
我曾经使用脚本通过更新表单来更改图像上的文本。
当我在预安装了所有模块的共享主机上时,它一开始工作得很好。
我搬到了 vps,我必须自己安装所有东西,现在脚本不再起作用。
php 页面可以显示,但是当我更新时,文本不会像以前那样显示。
以下是共享主机上仍然有效的页面示例: http://nyanpuffle.com/auntarctic/ 密码是 1234
这里是页面示例不起作用的 vps: http://www.clubpenguincheatsy.com/cptrackers/auntarctic/ 密码是 1234
这里是使用的编码副本:
<TITLE>Tracker</TITLE>
<body bgcolor="#4b7bb2">
<font face="arial">
<center>
<?php
$submit = $_POST['submit']; // Gets If It has been Submitted
if($submit){ // If submitted do this.
$password = $_POST['password']; // Get the password they submitted
$status = $_POST['status']; // Get the status they submitted
$server = $_POST['server']; // Get the server they submitted
$room = $_POST['room']; // Get the room they submitted
//Now We Secure it.
if($password == "1234"){
//Now We Generate the image and stuff.
$im = imagecreatefrompng("in.png");
// Make RGB Colour For Writing
$colour = imagecolorallocate($im, 255, 255, 255); // I want mine in red(This is black). So I am just
//Gonna find out the rgb code
$font = 'BurbankBigRegular-Bold.ttf'; //
//This ^ Is our font, It has to be the exact name and in the right folder.
//Draw Text
imagettftext($im, 20, 0, 100, 68, $colour, $font, $status);
imagettftext($im, 20, 0, 95, 95, $colour, $font, $server);
imagettftext($im, 20, 0, 85, 127, $colour, $font, $room);
//Create Image
imagepng($im,'out.png');
// Destroy - Save Server Resources
imagedestroy($im);
echo "<b> Updated! </b>";
}else
{
echo "<p><b>Incorrect Password!</b></p>";
}
}
//This form remebers what they put, so they dont have to keep typing it in.
// $_SERVER['PHP_SELF'] Means Get this document to submit to.
// If you know html this will be familiar.
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" />
<p>Password: <input type="password" name="password" id="password" value="<?php echo $_POST['password']; ?>"/></p>
<p>Status: <select name="status"> <option value="">Select...</option>
<option value="Online"> Online</option>
<option value="Offline"> Offline</option>
<option value="Tracking..."> Tracking</option>
</select>
</p>
<p>Server: <input type="text" id="server" name="server" value="<?php echo $_POST['server']; ?>"/></p>
<p>Room: <input type="text" id="room" name="room" value="<?php echo $_POST['room']; ?>"/></p>
<p><input type="submit" id="submit" name="submit"/></p>
</form>
<p>Tracker:</p>
<p><img src="out.png" alt="Tracker" /></P>
<a href="http://ClubPenguincheatsy.com/cptrackers"s>Back to Tracker Dashbaord</a>
</center>
VPS 在 Ubuntu 上运行,我安装了 PHP、MYSQL 和 Apache。
I used to use a script to change the text on an image via update form.
It worked perfectly at first while I was on a shared host with all modules pre-installed.
I moved to a vps where I had to install everything myself and now the script no longer works.
The php page is able to be displayed but when I update, the text does not show up like it used to.
Here is an example of the page on the shared host that still works:
http://nyanpuffle.com/auntarctic/ Password is 1234
Here is an example of the page on the vps that does not work:
http://www.clubpenguincheatsy.com/cptrackers/auntarctic/ Password is 1234
Here is a copy of the coding used:
<TITLE>Tracker</TITLE>
<body bgcolor="#4b7bb2">
<font face="arial">
<center>
<?php
$submit = $_POST['submit']; // Gets If It has been Submitted
if($submit){ // If submitted do this.
$password = $_POST['password']; // Get the password they submitted
$status = $_POST['status']; // Get the status they submitted
$server = $_POST['server']; // Get the server they submitted
$room = $_POST['room']; // Get the room they submitted
//Now We Secure it.
if($password == "1234"){
//Now We Generate the image and stuff.
$im = imagecreatefrompng("in.png");
// Make RGB Colour For Writing
$colour = imagecolorallocate($im, 255, 255, 255); // I want mine in red(This is black). So I am just
//Gonna find out the rgb code
$font = 'BurbankBigRegular-Bold.ttf'; //
//This ^ Is our font, It has to be the exact name and in the right folder.
//Draw Text
imagettftext($im, 20, 0, 100, 68, $colour, $font, $status);
imagettftext($im, 20, 0, 95, 95, $colour, $font, $server);
imagettftext($im, 20, 0, 85, 127, $colour, $font, $room);
//Create Image
imagepng($im,'out.png');
// Destroy - Save Server Resources
imagedestroy($im);
echo "<b> Updated! </b>";
}else
{
echo "<p><b>Incorrect Password!</b></p>";
}
}
//This form remebers what they put, so they dont have to keep typing it in.
// $_SERVER['PHP_SELF'] Means Get this document to submit to.
// If you know html this will be familiar.
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" />
<p>Password: <input type="password" name="password" id="password" value="<?php echo $_POST['password']; ?>"/></p>
<p>Status: <select name="status"> <option value="">Select...</option>
<option value="Online"> Online</option>
<option value="Offline"> Offline</option>
<option value="Tracking..."> Tracking</option>
</select>
</p>
<p>Server: <input type="text" id="server" name="server" value="<?php echo $_POST['server']; ?>"/></p>
<p>Room: <input type="text" id="room" name="room" value="<?php echo $_POST['room']; ?>"/></p>
<p><input type="submit" id="submit" name="submit"/></p>
</form>
<p>Tracker:</p>
<p><img src="out.png" alt="Tracker" /></P>
<a href="http://ClubPenguincheatsy.com/cptrackers"s>Back to Tracker Dashbaord</a>
</center>
The VPS is ran on Ubuntu and I have PHP,MYSQL, and Apache installed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的原始代码在所有变量上抛出
未定义的变量:
错误,您应该始终在使用变量之前设置它们,这包括 $_POST 变量,您应该启用错误报告error_reporting(E_ALL)
开发时更改error_reporting(0)
当您上传到实时站点时,您会看到停止图像处理/更新的错误。我已经通过一些更改修复了您的代码:
注意
htmlentities()
&表单中未使用$_SERVER['PHP_SELF']
。编辑:
摘自http://php.net/manual/en/function.imagettftext.php
Your original code throws
Undefined variable:
errors on all your variables, you should always set variables before using them, this includes $_POST variables, you should enable error reportingerror_reporting(E_ALL)
when developing and then change tooerror_reporting(0)
when you upload to a live site then your see the errors that are stopping the processing/updating of the image.Ive fixed your code with some changes:
Notice the
htmlentities()
& the non use of$_SERVER['PHP_SELF']
in the form.EDIT:
Taken from http://php.net/manual/en/function.imagettftext.php
替换为:
replace with :