GD (dynamic images) with values pulled from a database ????

images php coding issues or problems here.

Moderators: macek, egami, gesf

GDUser
New php-forum User
New php-forum User
Posts: 2
Joined: Wed Sep 14, 2005 5:07 pm

GD (dynamic images) with values pulled from a database ????

Postby GDUser » Wed Sep 14, 2005 5:13 pm

Hi there,

Hoping that I can get some help on a GD Coding issue that I've been struggling with for the last 2 days ... (searched everywhere on the net, but cant find an answer). Basically what I need to achieve is,

Establish a connection to my MySQL db, retrieve all the records and display them on the page. Each record contains data from the following fields: UniqueID, Category and Name

For each record (containing the fields listed above) that I display on the page, I also want to dynamically create an image using the GD function. The text that needs to appear on the dynamic image needs to be pulled from the database (using the Name field value).

Can someone please provide assistance on how to achieve this? I have made many attempts, but none have yet been successful. Here is my latest attempt (see #3 below). Not sure if this method is most appropriate or not???

1) This is the code for the php page (RetrieveAllRecords.php) that I use to retrieve all records from a MySQL db. I have tested this page and it works!

Code: Select all

<html>
<body>
<head>
<title>***This is my Retrieve Records Page !****</title>
</head>

<?php
$dbhost = 'mysql.xxx.com.au;
$dbuser = 'username';
$dbpass = 'password';
$dbname = 'databasename';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);

$query  = "SELECT * FROM fonts";
$result = mysql_query($query);

while($row = mysql_fetch_assoc($result))
{
    echo "UniqueID :{$row['UniqueID']} <br>" .
         "Category : {$row['Category']} <br>" .
         "Name : {$row['Name']} <br><br>";
}
?>

</body>
</html>
2) This is another php page (GD.php) that I use to dynamically create an image (using a specified Font and TextString) using the GD command in PHP. I have tested this page and it works!

Code: Select all

<?php

header("Content-type: image/png");

$im = imagecreate(400, 30);
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
$path2fonts  = $DOCUMENT_ROOT."/ttf";
$font = 'asenine';
$TextString = 'This is the TextString to display for the font';

imagettftext($im, 20, 0, 10, 20, $black, $path2fonts."/".$font, $TextString);

imagepng($im);
imagedestroy($im);

?>
3) Its only when I try to combine the contents/usage of both these pages, that I run into problems.
The code / page below returns errors of:
"Parse error: parse error, expecting `','' or `';'' in D:\hshome\ animatio\ animationhut.com\ Combined.php on line 24"
This is the combined page (Combined.php) that I use:

Code: Select all

<html>
<body>
<head>
<title> *** Combined Retrieve Records Page + GD Page *** </title>
</head>

<?php
$dbhost = 'mysql.xxx.com.au;
$dbuser = 'username';
$dbpass = 'password';
$dbname = 'databasename';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);

$query  = "SELECT * FROM fonts";
$result = mysql_query($query);

while($row = mysql_fetch_assoc($result))
{
    echo "UniqueID :{$row['UniqueID']} <br>" .
         "Category : {$row['Category']} <br>" .
         "Name : {$row['Name']} <br>".
         "Image of Font : <img src="GD.php"> <br><br>";
}
?>

</body>
</html>
Note: I have uploaded all of these files onto my live server - if it helps, you can view them at:
http://www.animationhut.com/RetrieveAllRecords.php
http://www.animationhut.com/gd.php
http://www.animationhut.com/Combine.php



thanks again everyone !!!!

:)

GDUser
New php-forum User
New php-forum User
Posts: 2
Joined: Wed Sep 14, 2005 5:07 pm

Postby GDUser » Wed Sep 14, 2005 6:06 pm

thanks everyone ....

I just got advised of the answer:

I also found some code that to pass to the GD page, in order to read a value for the GD TextString part:

Code: Select all

<?php

while($row = mysql_fetch_assoc($result))
{
echo "UniqueID :{$row['UniqueID']} <br>" .
"Category : {$row['Category']} <br>" .
"Name : {$row['Name']} <br>".
"Image of Font : <img src=\"GD.php?font={$row['Name']}\"> <br><br>";
}

?>



Hope it helps other newbies as well !


Return to “PHP coding => Images”

Who is online

Users browsing this forum: No registered users and 1 guest

cron