Jump to content

Recommended Posts

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.

 

Link to comment
https://forums.phpfreaks.com/topic/70825-image-from-mysql-data/
Share on other sites

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);

?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/70825-image-from-mysql-data/#findComment-356796
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.