Файл: id2759/CGI Version/fileman/images/chart.php
Строк: 38
<?php
header("Content-type:image/png");
$id = ImageCreate(180, 180);
$hcenter = ImageSX($id)/2;
$vcenter = ImageSY($id)/2;
$diameter = 160;
$black = ImageColorAllocate($id, 0, 0, 0);
$white = ImageColorAllocate($id, 255, 255, 255);
$pie_color[1] = ImageColorAllocate($id, 70, 130, 180);
$pie_color[2] = ImageColorAllocate($id, 255, 255, 255);
//the white back ground will be transparent
ImageFill($id, 0, 0, $white);
ImageColorTransparent($id, $white);
$total = $free + $used;
$n = 0;
//read the arguments into different arrays
$value[1] = $free;
$value[2] = $used;
$arc_rad[1] = $value[1] * 2 * pi(void);
$arc_rad[2] = $total * 2 * pi(void);
$arc_dec[1] = $value[1] * 360;
$arc_dec[2] = $total * 360;
//the base
$arc_rad[0] = 0;
$arc_dec[0] = 0;
//count the labels
for($i=1; $i<=2; $i++){
$idf = 1;
$hfw = ImageFontWidth($idf);
$vfw = ImageFontHeight($idf);
//calculate the percents
$perc[$i] = $value[$i]/$total;
$percstr[$i] = (string)number_format($perc[$i] * 100,1) . "%";
//calculate the arc and line positions
$arc_rad[$i] = $arc_rad[$i]/$total;
$arc_dec[$i] = $arc_dec[$i]/$total;
$hpos = Round($hcenter + ($diameter/2) * Sin($arc_rad[$i]));
$vpos = Round($vcenter + ($diameter/2) * Cos($arc_rad[$i]));
ImageLine($id, $hcenter, $vcenter, $hpos, $vpos, $black);
ImageArc($id, $hcenter, $vcenter, $diameter, $diameter, $arc_dec[$i-1], $arc_dec[$i], $black);
}
for($i=1; $i<=2; $i++){
$arc_rad_label = $arc_rad[$i-1] + 0.5 * $perc[$i] * 2 * pi(void);
$hpos = $hcenter + 0.8 * ($diameter/2) * Sin($arc_rad_label);
$vpos = $vcenter + 0.8 * ($diameter/2) * Cos($arc_rad_label);
ImageFillToBorder($id, $hpos, $vpos, $black, $pie_color[$i]);
}
ImagePng($id);
ImageDestroy($id);
?>