🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
先来了解几个函数: 1、画实直线:imageline($image, $x1, $y1, $x2, $y2, $color)。 2、画虚直线:imagedashedline($image, $x1, $y1, $x2, $y2, $color)。 3、定义直线粗细:imagesetthickness($image, $thickness)。 4、定义直线样式:imagesetstyle($image, $style)。$style通常是一个由多个色彩组成的数组。 5、定义笔刷:imagesetbrush($image, $brush)。$brush可以是填充色,也可以是图片。 代码如下: /* $img = imagecreatetruecolor(600, 600); $color1 = imagecolorallocate($img, 255, 0, 0); $color2 = imagecolorallocate($img, 255, 255, 255); $color3 = imagecolorallocate($img, 255, 255, 255); imagefill($img, 0, 0, $color1); imageline($img, 600, 0, 0, 600, $color2); imagedashedline($img, 0, 0, 500, 599, $color3); header('Content-type:image/jpeg'); imagejpeg($img); */ /* $img = imagecreatetruecolor(300, 300); $color1 = imagecolorallocate($img, 255, 0, 0); $color2 = imagecolorallocate($img, 132, 234, 111); $color3 = imagecolorallocate($img, 100, 34, 241); $color4 = imagecolorallocate($img, 255, 0, 255); $style = array($color1,$color2,$color1,$color2,$color1,$color2,$color3,$color4,$color3,$color4,$color3,$color4); imagesetstyle($img, $style); imagesetthickness($img, 35); imagefill($img, 0, 0, $color1); imageline($img, 0, 0, 300, 300, $color2); header('Content-type:image/jpeg'); imagejpeg($img); */ $img = imagecreate(600, 600); $red = imagecolorallocate($img, 255, 0, 0); imagefill($img, 0, 0, $red); $brush = imagecreate(20, 20); $white = imagecolorallocate($brush, 255, 255, 255); imagefill($brush, 0, 0, $white); imagesetbrush($img, $brush); imageline($img, 0, 0, 600, 600, IMG_COLOR_BRUSHED); header('Content-type:image/jpeg'); imagejpeg($img);