Click to See Complete Forum and Search --> : Graphing with PHP using GD - error !
coool
07-12-2007, 02:41 PM
hey guys,
I'm having problem when I'm excuting this code
<?php
header ("Content-type: image/jpg");
$img_handle = ImageCreate (230, 20) or die ("Cannot Create image");
$back_color = ImageColorAllocate ($img_handle, 0, 10, 10);
$txt_color = ImageColorAllocate ($img_handle, 233, 114, 191);
ImageString ($img_handle, 31, 5, 5, "My first Program with GD", $txt_color);
ImagePng ($img_handle);
?>
This is the output:
PNG IHDRPLTE r`LIDAT(бAMhF!a+(W&;xZi'J*DR+0w`fSc CYeGE*T,(Pe|&H;?&ֳ54I%ב[!i)1kg$;P Eo,{z:`̔,fS87ȐEE,N@4&gG2'D?<_FIENDB`
what's wrong with my code !
do you have any clue ?
bokeh
07-12-2007, 02:58 PM
You're sending output before the header.
artemis
07-13-2007, 07:18 AM
hey guys,
I'm having problem when I'm excuting this code
<?php
header ("Content-type: image/jpg");
ImagePng ($img_handle);
?>
If it's a png you want then the header should be:
<?php
header ("Content-type: image/png");
?>
bokeh
07-13-2007, 07:24 AM
If it's a png you want then the header should be:
<?php
header ("Content-type: image/png");
?>The theory is correct but in practice it makes no difference.
By the way "Content-Type" should have a capital "T".
coool
07-15-2007, 11:58 PM
I've fixed the header.. and they content-Type way of written ! ...
however, I've got the same problem.. :(
<?php
header ("Content-Type: image/png");
$img_handle = ImageCreate (230, 20) or die ("Cannot Create image");
$back_color = ImageColorAllocate ($img_handle, 0, 10, 10);
$txt_color = ImageColorAllocate ($img_handle, 233, 114, 191);
ImageString ($img_handle, 31, 5, 5, "My first Program with GD", $txt_color);
ImagePng ($img_handle);
?>
bokeh
07-16-2007, 07:48 AM
You're sending output before the header.Did you read this post?
coool
07-16-2007, 09:35 AM
I've got the problem solved..
I just saparated the codes..
image.php
<?php
header ("Content-type: image/jpg");
$image = ImageCreate (230, 20) or die ("Cannot Create image");
$back_color = ImageColorAllocate ($image, 1, 10, 10);
$text_color = ImageColorAllocate ($image, 233, 114, 191);
ImageString ($image, 31, 5, 5, "My first Program with GD", $text_color);
ImagePng ($image);
?>
page.php
<html>
<head></head>
<body>
<img src="image.php"/>
</body>
</html>
coool
07-16-2007, 09:36 AM
okay ! .. now how can have a graph ! with x-axis and y-axis taken from one table in MySQL query !
for example:
FruitsTable
fruitName numberAvailable
Apple 2
Orange 8
Banana 5
I want the x-axis to be my fruitName
and the y-axis to be the numberAvailable of the fruit
Query = "SELECT fruitName, numberAvailable FROM FruitsTable"
then ?
coool
07-26-2007, 02:16 PM
any simple code example please ?
:)
coool
07-27-2007, 09:17 AM
what i'm looking for is something similar to the attached picture
please take a look