Creating a dynamic png image using php - help please!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
TheOracle
Forum Commoner
Posts: 64
Joined: Mon Nov 22, 2004 4:56 am
Location: Bedford, UK

Creating a dynamic png image using php - help please!

Post 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??
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

If you request the script directly, what does it show then?
TheOracle
Forum Commoner
Posts: 64
Joined: Mon Nov 22, 2004 4:56 am
Location: Bedford, UK

Post by TheOracle »

If I run it as an include, it just displays a serious mess of funny characters (only way to describe it)...lol
TheOracle
Forum Commoner
Posts: 64
Joined: Mon Nov 22, 2004 4:56 am
Location: Bedford, UK

Post by TheOracle »

I also tested the GD extension in advance...and that works fine.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

By directly, he means navigate to that page / image.
Post Reply