Go4Expert

Go4Expert (http://www.go4expert.com/)
-   PHP (http://www.go4expert.com/forums/php/)
-   -   Graphing with PHP using GD - error ! (http://www.go4expert.com/forums/graphing-php-using-gd-error-t5235/)

coool 13Jul2007 01:10

Graphing with PHP using GD - error !
 
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 ?

pradeep 13Jul2007 10:08

Re: Graphing with PHP using GD - error !
 
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");


coool 16Jul2007 10:27

Re: Graphing with PHP using GD - error !
 
I've changed the header..

same problem.. :(

pradeep 16Jul2007 10:33

Re: Graphing with PHP using GD - error !
 
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);
 ?>


coool 16Jul2007 20:01

Re: Graphing with PHP using GD - error !
 
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>

coool 16Jul2007 20:02

Re: Graphing with PHP using GD - error !
 
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 18Jul2007 01:32

Re: Graphing with PHP using GD - error !
 
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

pradeep 18Jul2007 10:06

Re: Graphing with PHP using GD - error !
 
Check this out http://www.go4expert.com/showthread.php?t=344


All times are GMT +5.5. The time now is 04:35.