Page 1 of 1
[SOLVED] Drawing with php
Posted: Wed Mar 23, 2005 8:22 am
by rubberjohn
I have an array with around 70 ($hist) values in it, how can i graphically represent this as if it is a line graph where all of the lines are next to one another with no gaps in between. I cant seem to get any of the draw functions properly to achieve this.
Thanks
RJ
Posted: Wed Mar 23, 2005 8:39 am
by feyd
Posted: Wed Mar 23, 2005 8:57 am
by rubberjohn
yeah i looked at that but it seems a bit to OTT for what i need. Ill just try and get this working, cheers.
RJ
Posted: Wed Mar 23, 2005 9:05 am
by rubberjohn
before i go can you tell me why i am getting this when i try and use the drawing functions
Code: Select all
‰PNG IHDRÈ–æ²/Š PLTEÈÈÈéї––ÿB „„_IDATxœí™±n„0 †)^ÚåNrÞÇ‘¸ÝHäO}Ân 4w®Úþ— ÇŸý;ˆpý…$°LW¸‘
Posted: Wed Mar 23, 2005 9:10 am
by feyd
you used imagepng(), but didn't send a image/png content-type

Posted: Wed Mar 23, 2005 9:19 am
by rubberjohn
you mean this
Code: Select all
header ("Content-type: image/png");
Posted: Wed Mar 23, 2005 9:20 am
by Chris Corbyn
Yup...

Posted: Wed Mar 23, 2005 9:25 am
by rubberjohn
i have put that in but it is still doing that
Posted: Wed Mar 23, 2005 9:37 am
by feyd
are you echoing anything? maybe you should post your script?
Posted: Wed Mar 30, 2005 4:30 am
by rubberjohn
here it is, by the way this isn't the code that i originally wrote, i got this off the web just to try an see if the problem was my code or something else:
Code: Select all
<?php
header ("Content-type: image/png");
#$histogram = imagecreate(100,100);
#for ($v=0; $v>=count($hist); $v++){
#imageline($histogram, 5, 5, 5, 5);
#echo "THIS IS IN THE LOOP" . $v;
#}
#imageline($histogram, 5, 5, 5, 5, 0);
#imagejpeg($histogram);
#imagedestroy($histogram);
/* We need this in order to return a picture */
$graph_data = array(
"question" => "Are you addicted to PHP ?" ,
"yes" => 82 ,
"no" => 18
);
/* Create the images */
$im = ImageCreate(200,150) or die("could not create image !! <br>");
/* allocate the colors */
$background_color = ImageColorAllocate ($im, 200, 200, 200);
$text_color = ImageColorAllocate ($im, 233, 14, 91);
$bar_color = ImageColorAllocate ($im, 0, 0, 0);
$bar_color_fill = ImageColorAllocate ($im, 150, 150, 255);
/* draw some text .. */
ImageFill ($im,1,1,$background_color);
ImageString ($im, 3, 5, 5, $graph_data["question"], $text_color);
ImageString ($im, 2, 30, 130, "yes: ".$graph_data["yes"]."%" , $text_color);
ImageString ($im, 2, 110, 130, "no: ".$graph_data["no"]."%" , $text_color);
/* draw the bars */
ImageRectangle ($im, 30, 120 - $graph_data["yes"],50,120 ,$bar_color);
if($graph_data["yes"] > 2) { #so we won't fill the bg of the image ...
ImageFill ($im,31,119,$bar_color_fill);
}
ImageRectangle ($im, 110, 120 - $graph_data["no"],130,120 ,$bar_color);
if($graph_data["yes"] > 2) {
ImageFill ($im,111,119,$bar_color_fill);
}
/* returm image data */
ImagePng ($im);
?>
which gives me:
Code: Select all
Warning: Cannot modify header information - headers already sent by (output started at /home/ftpserver/www/homepage/student/engjbarn/drawtest.php:9) in /home/ftpserver/www/homepage/student/engjbarn/drawtest.php on line 10
‰PNG IHDRÈ–æ²/Š PLTEÈÈÈéї––ÿB „„_IDATxœí™±n„0 †)^ÚåNrÞÇ‘¸ÝHäO}Ân 4w®Úþ— ÇŸý;ˆpý…$°LW¸‘
Posted: Wed Mar 30, 2005 10:17 am
by feyd
you have an echo or some sort of output before the header call happens on line 2 (here) 10 in your script. Make sure to remove ALL blank lines before the php tag start.
thanks
Posted: Wed Apr 06, 2005 10:13 am
by rubberjohn
cheers i got that working