Jump to content

Need help with imagettftext.


asd3k2

Recommended Posts

Hi,

 

I have a small code to display some data from mysql db as .png image, however the image loads but it doesn't show any data on it.

 

php:

 

 

 
<?

    $username=""; 
    $password=""; 
    $database=""; 
    $host=""; 
     
    $player_name=$_GET['player_name'];
     

     
    mysql_connect($host,$username,$password); 
    @mysql_select_db($database) or die( "Unable to select database. Be sure the databasename exists and online is."); 
     

    $player_name = stripslashes($player_name);
    $player_name = mysql_real_escape_string($player_name);
     
     
     
    $query="SELECT * FROM characters WHERE name='$player_name'";
    $result=mysql_query($query);
    $i=mysql_num_rows($result); 
     
    if ($i == 1) 
    {
           
        $name=mysql_result($result,0,"name");
        $OnServer=mysql_result($result,0,"OnServer");
        $hours=mysql_result($result,0,"hours"); 
     
     

        header('Content-Type: image/png;');
        $im = @imagecreatefrompng('1.png') or die("Cannot select the correct image. Please contact the webmaster.");
        $text_color = imagecolorallocate($im, 197,197,199);
        $text_username = "$name";
        $text_hours = "$hours"; 
        $text_online = "$OnServer";
        $font = 'visitor2.ttf';
        imagettftext($im, 2, 0, 39, 15, $text_color, $font, $text_username); 
        imagettftext($im, 2, 0, 160, 15, $text_color, $font, $text_hours); 
        imagettftext($im, 2, 0, 297, 15, $text_color, $font, $text_online); 
        imagepng($im);
        imagedestroy($im);
    } else echo('Username is not in our database. Please try again.'); 
     
    mysql_close();
     
    ?>

 

html:

    <html>
    <head>
            <title>My title here</title>
    </head>
            <h1>Signature configuration.</h1>
            <p>Hello and welcome to the image configuration page.<br />
            Before you can make your signature, we need in-game name, exact as it is.</p>
           
            <form action="signature.php" method="get"> 
            Playername:
           <input type="Submit"> 
           </form>
     
     
    </body>
    </html>

 

sql dump: http://pastebin.com/zXHgCDpt

 

Any ideas? (it's 6am in here so I probably missed something obvious, sorry about that)

 

Link to comment
Share on other sites

Just tried this code out and added an id and name to the database.

 

I could see it fine, I made the text size from 2 to 10 or larger so I can actually see it.

 

Added text input to the form also, made text red, be sure you have the required font in same directory

<?php
if(isset($_GET['player_name']) && $_GET['player_name'] !=''){
    $username=""; 
    $password=""; 
    $database="characters"; 
    $host="localhost"; 
     
    $player_name=$_GET['player_name'];
     

     
    mysql_connect($host,$username,$password); 
    @mysql_select_db($database) or die( "Unable to select database. Be sure the databasename exists and online is."); 
     

    $player_name = stripslashes($player_name);
    $player_name = mysql_real_escape_string($player_name);
     
     
     
    $query="SELECT * FROM characters WHERE name='$player_name'";
    $result=mysql_query($query);
    $i=mysql_num_rows($result); 
     
    if ($i == 1) 
    {
           
        $name=mysql_result($result,0,"name");
        $OnServer=mysql_result($result,0,"OnServer");
        $hours=mysql_result($result,0,"hours"); 
     
     

        header('Content-Type: image/png;');
        $im = @imagecreatefrompng('1.png') or die("Cannot select the correct image. Please contact the webmaster.");
        $text_color = imagecolorallocate($im, 255,0,0);
        $text_username = "$name";
        $text_hours = "$hours"; 
        $text_online = "$OnServer";
        $font = 'visitor2.ttf';
        imagettftext($im, 10, 0, 39, 25, $text_color, $font, $text_username); 
        imagettftext($im, 10, 0, 160, 25, $text_color, $font, $text_hours); 
        imagettftext($im, 10, 0, 297, 25, $text_color, $font, $text_online); 
        imagepng($im);
        imagedestroy($im);
    } else {
    echo('Username is not in our database. Please try again.'); 
     }
     
   
    mysql_close();
     
    }
    ?>
     <html>
    <head>
            <title>My title here</title>
    </head>
            <h1>Signature configuration.</h1>
            <p>Hello and welcome to the image configuration page.<br />
            Before you can make your signature, we need in-game name, exact as it is.</p>
           
            <form action="" method="get"> 
            Playername:<input type="text" size="35" maxlength="35" name="player_name">
           <input type="Submit"> 
           </form>
     
     
    </body>
    </html>

 

Here's the code working using verdana font.

http://get.blogdns.com/test/sig-image.php

http://get.blogdns.com/test/sig-image.php?player_name=quick

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.