Page 1 of 1

drawing lines with a delay

Posted: Tue Dec 22, 2009 3:04 am
by the_metro_man
how do you draw lines with a delay of, say 5 seconds, between each line - below is my code - the problem is that the statement ImagePng($handle) draws the image after the plot and doesn't seem to accept being called more than once:

$x1=0;
$y1=0;
$first_one="yes";
while($nt=mysql_fetch_array($qt)){

$x2=$x1+$x_gap; // Shifting in X axis
$y2=$y_max-$nt[sales]; // Coordinate of Y axis

if($first_one=="no"){ // this is to prevent from starting $x1= and $y1=0
imageline ($handle,$x1, $y1,$x2,$y2,$txt_color); // Drawing the line between two points

ImagePng ($handle);
sleep(2);
}
$x1=$x2; // Storing the value for next draw
$y1=$y2;
$first_one="no"; // Now flag is set to allow the drawing
}

ImagePng ($handle);


thanks

Abbey

Re: drawing lines with a delay

Posted: Tue Dec 22, 2009 3:48 am
by requinix
PHP can't do things with a delay like that.

The easiest solution is to load the first image and use JavaScript to load the second, third, etc.

The best solution would be to create an animated GIF instead, but PHP's GD can't do that. You'd need something like ImageMagick or some other third-party extension/application.