TutorMe Posted September 27, 2007 Share Posted September 27, 2007 I am using a script I found on the web to try to create an image that displays information from a mysql database. Here's the code: <?php header('Content-type: image/png'); require_once('config.php'); $result = mysql_query("SELECT * FROM September"); while($row = mysql_fetch_array($result)) { $im = imagecreatefrompng ("userbar.png"); $color = imagecolorallocate($im, 0, 0, 0); $text = $row['username']; $font = 'font.ttf'; $size = 8; imagettftext($im, $size, 0, 15, 12, $color, $font, $text); imagepng($im); imagedestroy($im); } mysql_close($con); ?> I'm sorry for posting a lot of code, but I can't figure out why it wont display the data. I can see the background image fine, but no text appears. Quote Link to comment https://forums.phpfreaks.com/topic/70825-image-from-mysql-data/ Share on other sites More sharing options...
TutorMe Posted September 27, 2007 Author Share Posted September 27, 2007 Bump -- any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/70825-image-from-mysql-data/#findComment-356736 Share on other sites More sharing options...
BlueSkyIS Posted September 27, 2007 Share Posted September 27, 2007 is $font in your include path? Quote Link to comment https://forums.phpfreaks.com/topic/70825-image-from-mysql-data/#findComment-356738 Share on other sites More sharing options...
TutorMe Posted September 27, 2007 Author Share Posted September 27, 2007 I figured out how to do it. It may not be the best way, but it gets it done. <?php header("Content-type: image/png"); require_once('config.php'); mysql_select_db("bdays", $con); $result = mysql_query("SELECT * FROM September"); while($row = mysql_fetch_array($result)) { if ($row['day'] == date('d')) $list = $row['username'] . " "; } mysql_close($con); $string = $list; $im = imagecreatefrompng("userbar.png"); $orange = imagecolorallocate($im, 220, 210, 60); $px = (imagesx($im) - 7.5 * strlen($string)) / 2; imagestring($im, 3, $px, 9, $string, $orange); imagepng($im); imagedestroy($im); ?> Quote Link to comment https://forums.phpfreaks.com/topic/70825-image-from-mysql-data/#findComment-356796 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.