Jump to content

Image from mysql data


TutorMe

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.