asd3k2 Posted March 3, 2012 Share Posted March 3, 2012 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) Quote Link to comment https://forums.phpfreaks.com/topic/258164-need-help-with-imagettftext/ Share on other sites More sharing options...
batwimp Posted March 3, 2012 Share Posted March 3, 2012 It doesn't look like you have a text box to capture the name in the form. Quote Link to comment https://forums.phpfreaks.com/topic/258164-need-help-with-imagettftext/#findComment-1323413 Share on other sites More sharing options...
QuickOldCar Posted March 3, 2012 Share Posted March 3, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/258164-need-help-with-imagettftext/#findComment-1323414 Share on other sites More sharing options...
asd3k2 Posted March 3, 2012 Author Share Posted March 3, 2012 Ohh well. I still can't see anything in the image. : ( Quote Link to comment https://forums.phpfreaks.com/topic/258164-need-help-with-imagettftext/#findComment-1323428 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.