Page 1 of 1
PNG image help please
Posted: Fri Jun 17, 2005 2:08 pm
by dnathe4th
I'm trying to generate a picture with dots on it, the coordinates of the dots provided by a database table with the format of ID, X-co, Y-co
Code: Select all
<?PHP
$im = ImageCreateFromPNG("1.png") or die("No go on the PNG");
$size = '12';
$angle = '0';
$font = "Bamboo.ttf";
$textstr = "*";
mysql_connect("www.freesql.org","dnathe4th","THISISNOTMYPASSWORD") or die("Unable to connect");
@mysql_select_db("DNA_Fury_members") or die( "Unable to select database");
$query = "SELECT * FROM click_research";
$result = mysql_query($query) or die("Unable to submit query");
$num = mysql_numrows($result);
mysql_close();
$i = 0;
while($i < $num)
{
$color = ImageColorAllocate($im, rand(0, 100), rand(0, 100), rand(0, 100)) or die("Unable to allocate color");
$x = mysql_result($result, $i, "x");
$y = mysql_result($result, $i, "y");
ImageTTFText($im, $size, $angle, $x, $y, $color, $font, $textstr) or die("Could not do whatever this does");
$i++;
};
header("Content-Type: image/x-png");
echo ImagePNG($im);
?>
Ignore all the random Die statements, those were just my troubleshooting. Most of the code was copied and pasted from other places, then modified, which explains why it doesnt work. Can someone please help me here?
Posted: Fri Jun 17, 2005 2:52 pm
by John Cartwright
what is the error you are getting?
Posted: Fri Jun 17, 2005 2:54 pm
by onion2k
Don't echo the call to ImagePNG($im). Just use ImagePNG($im);.
Posted: Fri Jun 17, 2005 3:12 pm
by dnathe4th
ya i took out the echo after I posted, but it still doesn't work. There is no error, the page just doesn't come up when I view it in a browser. Is there any way I can run it to get an error? That would help with troubleshooting.
Posted: Sat Jun 18, 2005 3:51 am
by onion2k
dnathe4th wrote:Is there any way I can run it to get an error? That would help with troubleshooting.
Comment out lines 26 and 27.
Posted: Sat Jun 18, 2005 5:38 am
by dnathe4th
nah, even after commenting out lines 26 and 27 the page is still just blank when i try to access it.

Posted: Sat Jun 18, 2005 8:17 am
by onion2k
dnathe4th wrote:nah, even after commenting out lines 26 and 27 the page is still just blank when i try to access it.

Line 14: mysql_num_rows() is missing an _
Posted: Sat Jun 18, 2005 8:58 am
by dnathe4th
i put the _ in the num_rows but its still not showing anything. I don't know what else to try
Posted: Sat Jun 18, 2005 10:53 am
by onion2k
You're closing your mysql connection and then trying to use the result in the loop.
Try this:
Code: Select all
<?php
$im = ImageCreateTrueColor(200,200);
$size = '12';
$angle = '0';
$font = "Bamboo.ttf";
$textstr = "*";
mysql_connect("www.freesql.org","dnathe4th","THISISNOTMYPASSWORD");
@mysql_select_db("DNA_Fury_members");
$result = mysql_query("SELECT * FROM click_research");
while($record = mysql_fetch_object($result))
{
$color = ImageColorAllocate($im, rand(0, 100), rand(0, 100), rand(0, 100));
$x = $record->x;
$y = $record->y;
ImageTTFText($im, $size, $angle, $x, $y, $color, $font, $textstr);
};
header("Content-Type: image/png");
ImagePNG($im);
?>
Note that I've made it create a new image instead of opening one.. that was just me checking it'd work.
Posted: Sat Jun 18, 2005 11:04 am
by dnathe4th
onion did that work for you? its still not working for me. Still no image if i open it directly, and if i open a page with <IMG src=whatever.php> i just get a broken image. I used the exact code u pasted there onion, save, i changed my password.
Posted: Sat Jun 18, 2005 12:11 pm
by onion2k
My version is below, I had to tweak a few things to get rid of the database stuff. Works fine. I take it you definitely have GD installed with the FreeType library?
Code: Select all
<?php
$im = ImageCreate(200,200);
$color = ImageColorAllocate($im, 255, 255, 255);
$size = '12';
$angle = '0';
$font = "YIKES!__.TTF";
$textstr = "*";
$num = 10;
// mysql_connect("www.freesql.org","dnathe4th","THISISNOTMYPASSWORD") or die("Unable to connect");
// @mysql_select_db("DNA_Fury_members") or die( "Unable to select database");
// $result = mysql_query("SELECT * FROM click_research");
//while($record = mysql_fetch_object($result))
//{
$color = ImageColorAllocate($im, rand(0, 100), rand(0, 100), rand(0, 100));
//$x = $record->x;
//$y = $record->y;
$x = rand(0,200);
$y = rand(0,200);
ImageTTFText($im, $size, $angle, $x, $y, $color, $font, $textstr);
//};
header("Content-Type: image/png");
ImagePNG($im);
?>