Heres a page, may not work as intended with PHP 4.2.*,
call it like <img src="pie.php?slice[1]=2&slice[2]=4&slice[3]=9&slice[4]=5&slice[5]=11">
Hope this helps.
//Karv
----------pie.php-----------------
<?
// initialize some variables
$sum = 0;
$degrees = Array();
$diameter = 200;
$radius = $diameter/2;
// calculate sum of slices
for ($x=1; $x<=5; $x++)
{
$sum += $slice[$x];
}
// convert each slice into corresponding percentage of 360-degree circle
for ($y=1; $y<=5; $y++)
{
$degrees[$y] = ($slice[$y]/$sum) * 360;
}
// set up image and colours
Header("Content-Type: image/png"

;
$im = ImageCreate(300, 300);
$red = ImageColorAllocate($im, 255, 0, 0);
$blue = ImageColorAllocate($im, 0, 0, 255);
$green = ImageColorAllocate($im, 0, 255, 0);
$yellow = ImageColorAllocate($im, 255, 255, 0);
$black = ImageColorAllocate($im, 0, 0, 0);
$white = ImageColorAllocate($im, 255, 255, 255);
// fill image with white
ImageFill($im, 0, 0, $white);
// draw baseline
ImageLine($im, 150,150, 225, 150, $black);
for ($z=1; $z<=5; $z++)
{
// calculate and draw arc corresponding to each slice
ImageArc($im, 150, 150, $diameter, $diameter, $last_angle,($last_angle+$degrees[$z]), $black);
$last_angle = $last_angle+$degrees[$z];
// calculate coordinate of end-point of each arc by obtaining
// length of segment and adding radius
// remember that cos() and sin() return value in radians
// and have to be converted back to degrees!
$end_x = round(150 + ($radius * cos($last_angle*pi()/180)));
$end_y = round(150 + ($radius * sin($last_angle*pi()/180)));
// demarcate slice with another line
ImageLine($im, 150, 150, $end_x, $end_y, $black);
}
// this section is meant to calculate the mid-point of each slice
// so that it can be filled with colour
// initialize some variables
$prev_angle = 0;
$pointer = 0;
for ($z=1; $z<=5; $z++)
{
// to calculate mid-point of a slice, the procedure is to use an angle bisector
// and then obtain the mid-point of that bisector
$pointer = $prev_angle + $degrees[$z];
$this_angle = ($prev_angle + $pointer) / 2;
$prev_angle = $pointer;
// get end-point of angle bisector
$end_x = round(150 + ($radius * cos($this_angle*pi()/180)));
$end_y = round(150 + ($radius * sin($this_angle*pi()/180)));
// given start point (150,150) and end-point above, mid-point can be
// calculated with standard mid-point formula
$mid_x = round((150+($end_x))/2);
$mid_y = round((150+($end_y))/2);
// depending on which slice, fill with appropriate colour
if ($z == 1)
{
// Fill the new slice with colour ($im, pos x, pos y, bordercolour, fillcolour)
ImageFillToBorder($im, $mid_x, $mid_y, $black, $red);
// this line adds the label, ($im, FONTSIZE, position, x position y, TEXT, COLOUR)
ImageString($im, 3, $mid_x, $mid_y, a, $black);
}
else if ($z == 2)
{
ImageFillToBorder($im, $mid_x, $mid_y, $black, $blue);
ImageString($im, 3, $mid_x, $mid_y, test, $black);
}
else if ($z == 3)
{
ImageFillToBorder($im, $mid_x, $mid_y, $black, $green);
ImageString($im, 3, $mid_x, $mid_y, piccy, $black);
}
else if ($z == 4)
{
ImageFillToBorder($im, $mid_x, $mid_y, $black, $yellow);
ImageString($im, 3, $mid_x, $mid_y, should, $black);
}
else if ($z == 5)
{
ImageFillToBorder($im, $mid_x, $mid_y, $black, $white);
ImageString($im, 3, $mid_x, $mid_y, show, $black);
}
}
// Image title
ImageString($im, 5, 100, 10, "You like Pie", $black);
// output to browser
ImagePNG($im);
?> ______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.