PHP imagettfext 不显示工作

发布于 2024-11-27 00:31:39 字数 3066 浏览 0 评论 0原文

我曾经使用脚本通过更新表单来更改图像上的文本。

当我在预安装了所有模块的共享主机上时,它一开始工作得很好。

我搬到了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鲸落 2024-12-04 00:31:39

您的原始代码在所有变量上抛出 未定义的变量: 错误,您应该始终在使用变量之前设置它们,这包括 $_POST 变量,您应该启用错误报告 error_reporting(E_ALL) 开发时更改 error_reporting(0) 当您上传到实时站点时,您会看到停止图像处理/更新的错误。

我已经通过一些更改修复了您的代码:

<?php 
header("Cache-Control: no-cache, must-revalidate"); //remind the browser not to cache the image
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
error_reporting(E_ALL); //Change to 0 when live
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
   <title>Tracker</title>
  </head>

  <body bgcolor="#4b7bb2">
   <font face="arial">
   <center>
 <?php
    $password=''; //pre-set thos vars
    $status='';
    $server='';
    $room='';

    if(isset($_POST['submit'])){
        $password = $_POST['password'];
        if($password == "1234"){
            $status = $_POST['status'];
            $server = $_POST['server'];
            $room = $_POST['room'];

            $im = imagecreatefrompng("in.png");
            $colour = imagecolorallocate($im, 255, 255, 255);
            $font = 'BurbankBigRegular-Bold.ttf'; //

            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);
            imagepng($im,'out.png');
            imagedestroy($im);
            $result="<b> Updated! </b>";
        }else{
            $result="<p><b>Incorrect Password!</b></p>";
        }
    }
    echo (isset($result))?$result:'';
    ?>
    <form action="" method="POST" />
    <p>Password: <input type="password"  name="password" value="<?php echo htmlentities($password); ?>"/></p>

    <p>Status: <select name="status">
    <option value="">Select...</option>
    <?php 
    echo "<option value=\"Online\""; if($status=='Online'){ echo" selected=\"selected\"";} echo"> Online</option>\n";
    echo "<option value=\"Offline\""; if($status=='Offline'){ echo" selected=\"selected\"";} echo"> Offline</option>\n";
    echo "<option value=\"Tracking...\""; if($status=='Tracking...'){ echo" selected=\"selected\"";} echo"> Tracking</option>\n";
    ?>
    </select>
    </p>

    <p>Server: <input type="text" name="server" value="<?php echo htmlentities($server); ?>"/></p>
    <p>Room: <input type="text" name="room" value="<?php echo htmlentities($room); ?>"/></p>
    <p><input type="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>
</body>
</html>

注意 htmlentities() &表单中未使用 $_SERVER['PHP_SELF']

编辑:
摘自http://php.net/manual/en/function.imagettftext.php

您要使用的 TrueType 字体的路径。

取决于 PHP 使用的 GD 库的版本,何时
字体文件不以前导 / 开头,则 .ttf 将被附加到
文件名和库将尝试搜索该文件名
沿着库定义的字体路径。

当使用低于2.0.18的GD库版本时,空格
字符而不是分号被用作“路径分隔符”
对于不同的字体文件。无意中使用此功能将
导致警告消息:警告:无法找到/打开字体。为了
对于这些受影响的版本,唯一的解决方案是将字体移动到
不包含空格的路径。

在许多情况下,字体与脚本位于同一目录中
使用下面的技巧将缓解任何包含问题。

<?php
// Set the enviroment variable for GD
putenv('GDFONTPATH=' . realpath('.'));
// Name the font to be used (note the lack of the .ttf extension)
$font = 'BurbankBigRegular-Bold';
?>

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 reporting error_reporting(E_ALL) when developing and then change too error_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:

<?php 
header("Cache-Control: no-cache, must-revalidate"); //remind the browser not to cache the image
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
error_reporting(E_ALL); //Change to 0 when live
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
   <title>Tracker</title>
  </head>

  <body bgcolor="#4b7bb2">
   <font face="arial">
   <center>
 <?php
    $password=''; //pre-set thos vars
    $status='';
    $server='';
    $room='';

    if(isset($_POST['submit'])){
        $password = $_POST['password'];
        if($password == "1234"){
            $status = $_POST['status'];
            $server = $_POST['server'];
            $room = $_POST['room'];

            $im = imagecreatefrompng("in.png");
            $colour = imagecolorallocate($im, 255, 255, 255);
            $font = 'BurbankBigRegular-Bold.ttf'; //

            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);
            imagepng($im,'out.png');
            imagedestroy($im);
            $result="<b> Updated! </b>";
        }else{
            $result="<p><b>Incorrect Password!</b></p>";
        }
    }
    echo (isset($result))?$result:'';
    ?>
    <form action="" method="POST" />
    <p>Password: <input type="password"  name="password" value="<?php echo htmlentities($password); ?>"/></p>

    <p>Status: <select name="status">
    <option value="">Select...</option>
    <?php 
    echo "<option value=\"Online\""; if($status=='Online'){ echo" selected=\"selected\"";} echo"> Online</option>\n";
    echo "<option value=\"Offline\""; if($status=='Offline'){ echo" selected=\"selected\"";} echo"> Offline</option>\n";
    echo "<option value=\"Tracking...\""; if($status=='Tracking...'){ echo" selected=\"selected\"";} echo"> Tracking</option>\n";
    ?>
    </select>
    </p>

    <p>Server: <input type="text" name="server" value="<?php echo htmlentities($server); ?>"/></p>
    <p>Room: <input type="text" name="room" value="<?php echo htmlentities($room); ?>"/></p>
    <p><input type="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>
</body>
</html>

Notice the htmlentities() & the non use of $_SERVER['PHP_SELF'] in the form.

EDIT:
Taken from http://php.net/manual/en/function.imagettftext.php

The path to the TrueType font you wish to use.

Depending on which version of the GD library PHP is using, when
fontfile does not begin with a leading / then .ttf will be appended to
the filename and the library will attempt to search for that filename
along a library-defined font path.

When using versions of the GD library lower than 2.0.18, a space
character, rather than a semicolon, was used as the 'path separator'
for different font files. Unintentional use of this feature will
result in the warning message: Warning: Could not find/open font. For
these affected versions, the only solution is moving the font to a
path which does not contain spaces.

In many cases where a font resides in the same directory as the script
using it the following trick will alleviate any include problems.

<?php
// Set the enviroment variable for GD
putenv('GDFONTPATH=' . realpath('.'));
// Name the font to be used (note the lack of the .ttf extension)
$font = 'BurbankBigRegular-Bold';
?>
年华零落成诗 2024-12-04 00:31:39

$font = 'BurbankBigRegular-Bold.ttf';

替换为:

define ("_DOC_ROOT", dirname( __FILE__ ) ."/" );
$font = _DOC_ROOT.'dir_u_know/dir_u_know/BurbankBigRegular-Bold.ttf';

$font = 'BurbankBigRegular-Bold.ttf';

replace with :

define ("_DOC_ROOT", dirname( __FILE__ ) ."/" );
$font = _DOC_ROOT.'dir_u_know/dir_u_know/BurbankBigRegular-Bold.ttf';

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文