[SOLVED] Drawing with php

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
rubberjohn
Forum Contributor
Posts: 193
Joined: Fri Feb 25, 2005 4:03 am

[SOLVED] Drawing with php

Post 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
Last edited by rubberjohn on Wed Apr 06, 2005 10:14 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

rubberjohn
Forum Contributor
Posts: 193
Joined: Fri Feb 25, 2005 4:03 am

Post 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
rubberjohn
Forum Contributor
Posts: 193
Joined: Fri Feb 25, 2005 4:03 am

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

Post by feyd »

you used imagepng(), but didn't send a image/png content-type :)
rubberjohn
Forum Contributor
Posts: 193
Joined: Fri Feb 25, 2005 4:03 am

Post by rubberjohn »

you mean this

Code: Select all

header ("Content-type: image/png");
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Yup... :P
rubberjohn
Forum Contributor
Posts: 193
Joined: Fri Feb 25, 2005 4:03 am

Post by rubberjohn »

i have put that in but it is still doing that
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

are you echoing anything? maybe you should post your script?
rubberjohn
Forum Contributor
Posts: 193
Joined: Fri Feb 25, 2005 4:03 am

Post 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ÈÈÈé&#1111;––ÿB „„_IDATxœí™±n„0 †)^ÚåNrÞÇ‘¸ÝHäO}Ân­ 4w®Úþ— ÇŸý;ˆpý…$°LW¸‘
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
rubberjohn
Forum Contributor
Posts: 193
Joined: Fri Feb 25, 2005 4:03 am

thanks

Post by rubberjohn »

cheers i got that working
Post Reply