Graphing with PHP using GD - error !

coool's Avatar
Go4Expert Member
hey guys,

I'm having problem when I'm excuting this code

PHP Code:
<?php
        header 
("Content-type: image/jpg");
        
$img_handle ImageCreate (23020) or die ("Cannot Create image");
        
$back_color ImageColorAllocate ($img_handle01010);
        
$txt_color ImageColorAllocate ($img_handle233114191);
        
ImageString ($img_handle3155,  "My first Program with GD"$txt_color);
        
ImagePng ($img_handle);
?>
This is the output:

Code:
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 ?
0
pradeep's Avatar, Join Date: Apr 2005
Team Leader
You are sending a image/png mime header but sending a PNG image data!
Change the header to

Code: PHP
header ("Content-type: image/png");
0
coool's Avatar
Go4Expert Member
I've changed the header..

same problem..
0
pradeep's Avatar, Join Date: Apr 2005
Team Leader
Code: PHP
<?php
         ob_start();
         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);
         ob_clean(); // clean the output buffer before sending the image data, nothing more than the image data should be sent
         ImagePng ($img_handle);
 ?>
0
coool's Avatar
Go4Expert Member
hmmm

I've tried your code.. It doesn't work !

but no worries, cuz the problem is already solved now

I just had to saparate the code..

image.php
PHP Code:
<?php
        header 
("Content-type: image/jpg");
        
$image ImageCreate (23020) or die ("Cannot Create image");
        
$back_color ImageColorAllocate ($image11010);
        
$text_color ImageColorAllocate ($image233114191);
        
ImageString ($image3155,  "My first Program with GD"$text_color);
        
ImagePng ($image);
?>
page.php
<html>
<head></head>
<body>

<img src="image.php"/>

</body>
</html>
0
coool's Avatar
Go4Expert Member
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 ?
0
coool's Avatar
Go4Expert Member
any help ! ..

just give a simple example where I have a graph that has x-axis and y-axis taken form a mySQL query from only one table between two columns

one column --> count(column1)
second column --> actual value of itself
0
pradeep's Avatar, Join Date: Apr 2005
Team Leader
Check this out http://www.go4expert.com/showthread.php?t=344