Here's a modified version of _theworks's code. My example uses TV.com's way of grabbing the pie's size and colors. I also added a small piece of code to smooth everything out. I hope this helps you out...
<?
// image data
$_owidth = 150;
$_oheight = 150;
$_pdepth = 50;
// color palette
$_pallete = array(
array(51, 204, 0), // 0: dark green
array(102, 255, 0), // 1: light green
array(153, 255, 0), // 2: lighter green
array(204, 255, 0), // 3: yellowish green
array(255, 255, 0), // 4: yellow
array(255, 204, 0), // 5: opaque orange
array(255, 153, 0), // 6: orange
array(255, 102, 0), // 7: opaque red
array(204, 51, 0), // 8: red
array(204, 0, 0) // 9: dark red
);
// dynamic image data
$_rwidth = $_owidth * 2;
$_rheight = $_oheight * 2;
$_pwidth = $_rwidth - $_pdepth;
$_pheight = $_rheight - ($_pdepth * 3);
$_xcenter = $_rwidth / 2;
$_ycenter = ($_rheight - $_pdepth) / 2;
// data validation
if (isset($_GET['idata']) && trim($_GET['idata']) !== "") {
$_data = explode(":", $_GET['idata']);
$_data_sum = array_sum($_data);
$_pieces = count($_data);
} else {
echo "error: missing idata variable...";
exit(1);
}
if (isset($_GET['icolor']) && trim($_GET['icolor']) !== "") {
$_clist = explode(":", $_GET['icolor']);
$_ccount = count($_clist);
if ($_ccount < $_pieces) {
echo "error: invalid number of colors";
exit(1);
} else {
for ($i=0; $i<$_ccount; $i++) {
$_colors[$i] = $_pallete[$_clist[$i]];
}
}
} else {
$_colors = $_pallete;
}
// convert values to angles
for ($i=0; $i<$_pieces; $i++) {
$_angle[$i] = (($_data[$i] / $_data_sum) * 360);
$_angle_sum[$i] = array_sum($_angle);
}
// create render image
$_image = @imagecreate ($_rwidth, $_rheight);
$_black = imagecolorallocate($_image, 0, 0, 0);
$_white = imagecolorallocate($_image, 255, 255, 255);
imagefill($_image, 0, 0, $_white);
// create random colors
for ($i=0; $i<$_pieces; $i++) {
$_scolor[$i] = imagecolorallocate($_image, $_colors[$i][0], $_colors[$i][1], $_colors[$i][2]);
$_dcolor[$i] = imagecolorallocate($_image, ($_colors[$i][0]/1.5), ($_colors[$i][1]/1.5), ($_colors[$i][2]/1.5));
}
// create 3d effect
for ($z=0; $z<$_pdepth; $z++) {
for ($i=0; $i<$_pieces; $i++) {
imagefilledarc($_image, $_xcenter, ($_ycenter+$_pdepth)-$z, $_pwidth, $_pheight, $_angle_sum[$i-1], $_angle_sum[$i], $_dcolor[$i], IMG_ARC_PIE);
}
}
// create surface pie
for ($i=0; $i<$_pieces; $i++) {
imagefilledarc($_image, $_xcenter, $_ycenter, $_pwidth, $_pheight, $_angle_sum[$i-1], $_angle_sum[$i], $_scolor[$i], IMG_ARC_PIE);
}
// resample image
$_fimage = @imagecreatetruecolor($_owidth, $_oheight);
imagecopyresampled($_fimage, $_image, 0, 0, 0, 0, $_owidth, $_oheight, $_rwidth, $_rheight);
// output
header('Content-type: image/gif');
imagegif($_fimage);
imagedestroy($_fimage);
imagedestroy($_image);
?>
Use as follows:
filename.php?idata=800:400:420:560:380:1000&icolor=9:4:3:2:1:0
You can also use it without the icolor variable.
😃