Page 1 of 1

Creating a dynamic png image using php - help please!

Posted: Fri Jul 06, 2007 11:12 am
by TheOracle
Hi All,

I am trying to create a dynamic image for the front page of a site, and instead of displaying its just coming up with the good old IE red-x!

I'm sure I must have done something wrong:

Code: Select all

<?php
ob_start();
header("Content-type: image/png");
$img = "images/serverstats.png";
$img_handle=imageCreateFromPNG($img);
$color=ImageColorAllocate($img_handle, 0x31, 0x2E, 0xA3);

/* Get values from DB and turn into variables */
$sql=mysql_query("select count(*) from tc_services") or die(mysql_query());
$result=mysql_fetch_array($sql);

$serverno=$result['0'];

$sql1=mysql_query("select sum(slots) from tc_services") or die(mysql_query());
$result1=mysql_fetch_array($sql1);

$slotcount=$result1['0'];

$sql2=mysql_query("select count(*) from tc_games") or die(mysql_query());
$result2=mysql_fetch_array($sql2);

$sgames=$result2['0'];

$sql3=mysql_query('select count(*) from tc_servers where user_id != ""') or die(mysql_query());
$result3=mysql_fetch_array($sql3);

$dediservers=$result3['0'];
/* End variables */

ImageString($img_handle, 2, 10, 20, $serverno, $color); //just testing one of the variables to start with

ImagePng($img_handle);
ImageDestroy($img_handle);

?>
This code is called by a line in the html:

<img src="serverstats.php" />

All the files are in the right place, and the db connection is created in the original file, and that works... Just cant display the image??

Posted: Fri Jul 06, 2007 11:24 am
by feyd
If you request the script directly, what does it show then?

Posted: Fri Jul 06, 2007 11:36 am
by TheOracle
If I run it as an include, it just displays a serious mess of funny characters (only way to describe it)...lol

Posted: Fri Jul 06, 2007 11:38 am
by TheOracle
I also tested the GD extension in advance...and that works fine.

Posted: Fri Jul 06, 2007 12:25 pm
by superdezign
By directly, he means navigate to that page / image.