<?php

ob_start();

// First we creat the image
$pie = imagecreatetruecolor(130, 130);

// Now lets define some colours
$col[0]  = imagecolorallocate($pie,255,0,0);     // red
$col[1]  = imagecolorallocate($pie,0,128,0);     // green
$col[2]  = imagecolorallocate($pie,255,255,0);   // yellow
$col[3]  = imagecolorallocate($pie,0,0,128);     // navy
$col[4]  = imagecolorallocate($pie,255,0,255);   // fushcia
$col[5]  = imagecolorallocate($pie,0,128,128);   // teal
$col[6]  = imagecolorallocate($pie,192,192,192); // silver
$col[7]  = imagecolorallocate($pie,128,0,0);     // maroon
$col[8]  = imagecolorallocate($pie,0,255,0);     // lime
$col[9]  = imagecolorallocate($pie,128,128,0);   // olive
$col[10] = imagecolorallocate($pie,0,0,255);     // blue
$col[11] = imagecolorallocate($pie,128,0,128);   // purple
$col[12] = imagecolorallocate($pie,0,255,255);   // aqua
$col[13] = imagecolorallocate($pie,128,128,128); // gray
$col[14] = imagecolorallocate($pie,255,255,255); // white used for the background which we then make transparent
$col[15] = imagecolorallocate($pie,0,0,0);       // black

// Fill the image then make it transparent
imagecolortransparent($pie, $col[14]);
imagefill($pie,0,0,$col[14]);

$percentages = (!empty($_GET['pers'])) ? explode(',', $_GET['pers']) : '';

if(!is_array($percentages))
{
  imagestring($pie, 5, 50, 50, 'no percentages provided', $col[15]);
}
else
{
  // Set the start degree
  $x = 0;
  
  // Now loop through our percentages
  for ($z=0, $c=count($percentages); $z<$c; $z++) 
  {
    $degrees = (($percentages[$z]/100)*360);
    $color = imagecolorallocate($pie,mt_rand(20,255),mt_rand(20,255),mt_rand(20,255));
    imagefilledarc($pie,65,65,125,125,$x,($x+$degrees),$col[$z],IMG_ARC_PIE);
    $x+=$degrees;
  }
}

header("Content-type: image/gif");
imagegif($pie);

echo trim(ob_get_clean());

imagedestroy($pie);

?>