########
Bimage.php3
########
/*
Function description
$chartdata: Data, is an array element
$chartfont: Font Size
$chartdiameter: Determine the size of the cake (to see you hungry, hehe)
$chartlabel: Title, also an array element
$colorslice: array of colors, such as $tmp=array255,255,255); $colorslic =array ($tmp);
$colorborder: Border color, array
$colortext: text color, array
$colorbody: Background color, array
$file: Output Picture file name * *
function Bimage ($chartdata,
$chartfont,
$chartdiameter,
$chartlabel,
$colorslice,
$colorbody,
$colorborder,
$colortext,
$file
)
{
$chartdiameter = 150;
$chartfontheight =imagefontheight ($chartfont);
$d 1=10; $d 2=20; $d 3=30; $d 4=40; $d 5=50;
$chartdata =array ($d 1, $d 2, $d 3, $d 4, $d 5);
$chartlabel =array ("D1", "D2", "D3", "D4", "D5");
$chartwidth = $chartdiameter +20;
$chartheight = $chartdiameter +20+ (($chartfontheight +2) *count ($chartdata));
Header ("Content-type:image/gif");
$image =imagecreate ($chartwidth, $chartheight);
$colorbody =imagecolorallocate ($image, $colorbody [0], $colorbody [1], $colorbody [2]);
$colortext =imagecolorallocate ($image, $colortext [0], $colortext [1], $colortext [2]);
$colorborder =imagecolorallocate ($image, $colorborder [0], $colorborder [1], $colorborder [2]);
for ($i =0; $i {
$t =imagecolorallocate ($image, $colorslice [$i][0], $colorslice [$i][1], $colorslice [$i][2]);
$colorslice [$i]= $t;
}
for ($i =0; $i {
$charttotal + + $chartdata [$i];
}
$chartcenterx = $chartdiameter/2+10;
$chartcentery = $chartdiameter/2+10;
$degrees = 0;
for ($i =0; $i {
$startdegrees =round ($degrees);
$degrees + + ($chartdata [$i]/$charttotal) *360);
$enddegrees =round ($degrees);
$currentcolor = $colorslice [$i% (count ($colorslice))];
Imagearc ($image,
$chartcenterx,
$chartcentery,
$chartdiameter,
$chartdiameter,
$startdegrees,
$enddegrees,
$currentcolor);
List ($ARCX, $arcy) =circle_point ($startdegrees, $chartdiameter);
Imageline ($image,
$chartcenterx,
$chartcentery,
Floor ($chartcenterx + $ARCX),
Floor ($chartcentery + $arcy),
$currentcolor);
List ($ARCX, $arcy) =circle_point ($enddegrees, $chartdiameter);
Imageline ($image,
$chartcenterx,
$chartcentery,
Ceil ($chartcenterx + $ARCX),
Ceil ($chartcentery + $arcy),
$currentcolor);
$midpoint =round (($enddegrees-$startdegrees)/2) + $startdegrees);
List ($ARCX, $arcy) = Circle_point ($midpoint, $chartdiameter/2);
Imagefilltoborder ($image,
Floor ($chartcenterx + $ARCX),
Floor ($chartcentery + $arcy),
$currentcolor,
$currentcolor);
}
Imagearc ($image,
$chartcenterx,
$chartcentery,
$chartdiameter,
$chartdiameter,
0,360,
$colorborder);
Imagefilltoborder ($image,
Floor ($chartcenterx + ($chartdiameter/2) +2),
$chartcentery,
$colorborder,
$colorborder);
for ($i =0; $i {
$currentcolor = $colorslice [$i% (count ($colorslice))];
$liney = $chartdiameter +20+ ($i * ($chartfontheight +2));
Imagerectangle ($image,
10,
$liney,
20+ $chartfontheight,
$liney + $chartfontheight,
$colorbody);
Imagefilltoborder ($image,
12,
$liney +2,
$colorbody,
$currentcolor);
Imagestring ($image,
$chartfont,
40+ $chartfontheight,
$liney,
"$chartlabel [$i]: $chartdata [$i]",
$colortext);
}
Imagegif ($image, $file);
}
function radians ($degrees)
{
Return ($degrees * (pi ()/180.0));
}
function Circle_point ($degrees, $diameter)
{
$x =cos (radians ($degrees)) * ($diameter/2);
$y =sin (radians ($degrees)) * ($diameter/2);
Return (Array ($x, $y));
}
?>
###########
This is an example of a call
###########
Include ("bfunc.php3");
$chartdiameter = 250;
$chartfont = 5;
$d 1=10; $d 2=20; $d 3=30; $d 4=40; $d 5=50;
$chartdata =array ($d 1, $d 2, $d 3, $d 4, $d 5);
$chartlabel =array ("D1", "D2", "D3", "D4", "D5");
$colorbody =array (0XFF,0XFF,0XFF);
$colorborder =array (0x00,0x00,0x00);
$colortext =array (0XFF,0XFF,0XFF);
$color 1=array (0xff,0x00,0x00);
$color 2=array (0x00,0xff,0x00);
$color 3=array (0X00,0X00,0XFF);
$color 4=array (0xff,0xff,0x00);
$color 5=array (0XFF,0X00,0XFF);
$colorslice =array ($color 1, $color 2, $color 3, $color 4, $color 5);
$file = "Tj.gif"
Bimage ($chartdata,
$chartfont,
$chartdiameter,
$chartlabel,
$colorslice,
$colorbody,
$colorborder,
$colortext,
$file)
?>