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 //输出画布图像 11 imagepng($img); 12 ?>
php也能画图,但是好像用的不多,HTML5里的canvas跟这个原理差不多,但是用的人应该比PHP多。不知道PHP画图现在还有没有人用,只能用来画验证码了吗?
--------------------------------------------------------------------------------------------------------------------------------------------------
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 //画多边形,points是顶点坐标数组,num_points是顶点个数,妈蛋这个画不出来五角星,只能拼出来。还不如用直线画 11 $points = array(200,0,0,100,100,400,300,400,400,100); 12 imagepolygon($img, $points, 5, $green); 13 //输出画布图像 14 imagepng($img); 15 ?>
--------------------------------------------------------------------------------------------------------------------------------------------------
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 $degree18 = deg2rad(18);//直角三角形18度,改成弧度,一定是这里公式出了问题! 12 $a = $r*cos($degree18);//长边长度 13 $b = $r - $r*sin($degree18);//短边长度 14 //五个顶点坐标 15 $px1 = 200; 16 $py1 = 200; 17 $px2 = $px1+$a; 18 $py2 = $py1+$b; 19 $px3 = $px1+$b; 20 $py3 = $py1+$r+$a; 21 $px4 = $px1-$b; 22 $py4 = $py1+$r+$a; 23 $px5 = $px1-$a; 24 $py5 = $py1+$b; 25 //画多边形,points是顶点坐标数组,num_points是顶点个数,妈蛋这个画不出来五角星,只能拼出来。还不如用直线画 26 $points = array($px1,$py1,$px2,$py2,$px3,$py3,$px4,$py4,$px5,$py5); 27 // imagepolygon($img, $points, 5, $green); 28 //画五条线 29 imageline($img, $px1, $py1, $px3, $py3, $green); 30 imageline($img, $px1, $py1, $px4, $py4, $green); 31 imageline($img, $px2, $py2, $px4, $py4, $green); 32 imageline($img, $px2, $py2, $px5, $py5, $green); 33 imageline($img, $px3, $py3, $px5, $py5, $green); 34 35 //输出画布图像,怎么腿这么胖!! 36 imagepng($img); 37 38 ?>
--------------------------------------------------------------------------------------------------------------------------------------------------