1、PHP绘制多边形:
(1)空心多边形:imagepolygon($image, $points, $num_points, $color)。
(2)实心多边形:imagefilledpolygon($image, $points, $num_points, $color)。
代码如下:
$img = imagecreatetruecolor(600, 600);
imagefill($img, 0, 0, imagecolorallocate($img, 255, 0, 0));
$point = array(10,10,590,10,590,590,300,400);
//空心多边形
//imagepolygon($img, $point, 4, imagecolorallocate($img, 255, 255, 255));
//实心多边形
imagefilledpolygon($img, $point, 4, imagecolorallocate($img, 255, 255, 255));
header('Content-type:image/jpeg');
imagejpeg($img);
效果图如下:
![](https://box.kancloud.cn/32e30cea8bb7ebf61da799d7f8526333_614x618.jpg =500x400)
2、PHP绘制文字:
(1)横排文字:imagechar($image, $font, $x, $y, $c, $color)。
代码如下:
$img = imagecreatetruecolor(300, 300);
imagefill($img, 0, 0, imagecolorallocate($img, 123, 0, 123));
$str = 'http://www.baidu.com';
$str_len = strlen($str);
for($i=0;$i
$new_str = substr($str, $i,1);
imagechar($img, 5, 10+$i*10, 10, $new_str, imagecolorallocate($img, 255, 255, 255));
}
header('Content-type:image/jpeg');
imagejpeg($img);