开发者

PHP imagettfext not displaying working

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 开发者_StackOverflow中文版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.


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';
?>


$font = 'BurbankBigRegular-Bold.ttf';

replace with :

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜