<?php
//加header头,不然浏览器乱码
header("content-type: image/png");
//创建画布资源
$img = imagecreatetruecolor(500, 500);
//创建颜色
$green = imagecolorallocate($img, 0, 255, 0);
//画椭圆
// imagefilledellipse($img, 200, 200, 100, 100, $green);
$r = 100;//半径
$degree36 = deg2rad(36);//直角三角形18度,改成弧度
$l = 2*$r*sin($degree36);
$a = $l*cos($degree36);//长边1长度
$b = $l*sin($degree36);//短边1长度
$c = $l/2;//短边2长度
$d = $r*cos($degree36);//长边2长度
//五个顶点坐标
$px1 = 200;
$py1 = 200;
$px2 = $px1+$a;
$py2 = $py1+$b;
$px3 = $px1+$c;
$py3 = $py1+$r+$d;
$px4 = $px1-$c;
$py4 = $py1+$r+$d;
$px5 = $px1-$a;
$py5 = $py1+$b;
//画多边形,points是顶点坐标数组,num_points是顶点个数,妈蛋这个画不出来五角星,只能拼出来。还不如用直线画
$points = array($px1,$py1,$px2,$py2,$px3,$py3,$px4,$py4,$px5,$py5);
// imagepolygon($img, $points, 5, $green);
//画五条线
imageline($img, $px1, $py1, $px3, $py3, $green);
imageline($img, $px1, $py1, $px4, $py4, $green);
imageline($img, $px2, $py2, $px4, $py4, $green);
imageline($img, $px2, $py2, $px5, $py5, $green);
imageline($img, $px3, $py3, $px5, $py5, $green); //输出画布图像,终于正常了!
imagepng($img); ?>