php绘图(花),饼图

阅读更多
header("Content-type:image/png");//向浏览器输出文件头
$im=imagecreate(400, 400);
$yellow=imagecolorallocate($im, 255, 255, 180);
$blue=imagecolorallocate($im, 0,0,255);
$red=imagecolorallocate($im, 255,0,0);
for ($i = 1; $i < 360; $i++) {
	$temp=150*sin(2*deg2rad($i));
	$x=$temp*cos(deg2rad($i))+200;
	$y=$temp*sin(deg2rad($i))+200;
	imagesetpixel($im, $x, $y, $red);
	$temp=150*cos(2*deg2rad($i));
	$x=$temp*cos(deg2rad($i))+200;
	$y=$temp*sin(deg2rad($i))+200;
	imagesetpixel($im, $x, $y, $blue);
}
imagepng($im);//输出png图像
imagedestroy($im);//销毁图像资源,因其占用内存



//php绘制饼图
 $value ) {
		$angle [] = $value / $all * 360;
		$str = $key . ":" . round ( $value / $all * 100, 2 ) . "%";
		imagestring ( $im, 5, 10, ($i * 20 + 10), $str, $color [$i] );
		$i ++;
	}
	$s = 0;
	$i = 0;
	foreach ( $angle as $temp ) {
		imagefilledarc ( $im, 285, 150, 240, 240, $s, $s + $temp, $color [$i], 4 );
		$s += $temp;
		$i ++;
	}
	header ( 'Content-type:image/png' );
	imagepng ( $im );
	imagedestroy ( $im );
}
$arr = array ("111" => 1, "222" => 4, "333" => 5, "444" => 6, "555" => 3, "666" => 5.4, "777" => 2.6, "888" => 3.2, "999" => 1.6, "000" => 6.3 );
$re = pie2d ( $arr );

你可能感兴趣的:(php,image,绘图,饼图)