1 <?php 2 //加header头,不然浏览器乱码 3 header("content-type: image/png"); 4 //创建画布资源 5 $img = imagecreatetruecolor(500, 500); 6 //创建颜色 7 $green = imagecolorallocate($img, 0, 255, 0); 8 //画椭圆 9 // imagefilledellipse($img, 200, 200, 100, 100, $green); 10 $r = 100;//半径 11 $degree36 = deg2rad(36);//直角三角形18度,改成弧度 12 $l = 2*$r*sin($degree36); 13 $a = $l*cos($degree36);//长边1长度 14 $b = $l*sin($degree36);//短边1长度 15 $c = $l/2;//短边2长度 16 $d = $r*cos($degree36);//长边2长度 17 //五个顶点坐标 18 $px1 = 200; 19 $py1 = 200; 20 $px2 = $px1+$a; 21 $py2 = $py1+$b; 22 $px3 = $px1+$c; 23 $py3 = $py1+$r+$d; 24 $px4 = $px1-$c; 25 $py4 = $py1+$r+$d; 26 $px5 = $px1-$a; 27 $py5 = $py1+$b; 28 //画多边形,points是顶点坐标数组,num_points是顶点个数,妈蛋这个画不出来五角星,只能拼出来。还不如用直线画 29 $points = array($px1,$py1,$px2,$py2,$px3,$py3,$px4,$py4,$px5,$py5); 30 // imagepolygon($img, $points, 5, $green); 31 //画五条线 32 imageline($img, $px1, $py1, $px3, $py3, $green); 33 imageline($img, $px1, $py1, $px4, $py4, $green); 34 imageline($img, $px2, $py2, $px4, $py4, $green); 35 imageline($img, $px2, $py2, $px5, $py5, $green); 36 imageline($img, $px3, $py3, $px5, $py5, $green); 37 38 //输出画布图像,终于正常了! 39 imagepng($img); 40 41 ?>