<?php
$width=500;
$height=200;
$image=imagecreatetruecolor($width, $height+20);
// 用白色背景加黑色边框画个方框
$back = imagecolorallocatealpha($image, 50,50, 200,10);
imagefilledrectangle($image, 0, 0, $width,$height, $back);

// 用 alpha 值分配一些颜色
$yellow = imagecolorallocatealpha($image, 255, 255, 0, 75);
$red    = imagecolorallocatealpha($image, 255, 0, 0, 75);
$blue   = imagecolorallocatealpha($image, 0, 0, 255, 75);
$bai	= imagecolorallocatealpha($image, 255, 255, 255, 0);
include_once("include/config.php");
$Voteid=intval($_GET[voteid]);
$voteid=intval($_GET[voteid]);
$sql_total="select sum(totalnum) from vote where voteid= $Voteid group by voteid";
$result_total=query($sql_total);
$info_total=mysql_fetch_array($result_total);
$totalnum=$info_total[0];
$sql="select * from vote where voteid= $Voteid";
$result=query($sql);
$n=50;//间距
while ($info= mysql_fetch_array($result)) {
	$num=$info[totalnum];
	$title=$info[Votetitle];
	
	imagefilledrectangle($image,$n,($height*(1 - $num/$totalnum)), ($n+20),$height, $red);
	imagestring($image,3,$n+2,($height*(1 - $num/$totalnum)-$num-10),round($num/$totalnum *100).'% ('.$num.')',$yellow);
	$test=iconv("gb2312", "UTF-8", $title);
	imagettftext($image,10,0,($n-5),($height+15),$bai,"simkai.ttf",$test);
	$test=iconv("gb2312", "UTF-8", "总共人数：".$totalnum);
	imagettftext($image,10,0,($width-120),20,$bai,"simkai.ttf",$test);
	$n=$n+60;
}

// 不要忘记输出正确的 header！
header('Content-type: image/png');

// 最后输出结果
imagepng($image);
imagedestroy($image);

?>
