imagesetstyle
(PHP 4 >= 4.0.6, PHP 5, PHP 7)
imagesetstyle - 设置线条绘制的样式
描述
bool imagesetstyle ( resource $image , array $style )
imagesetstyle()设置所有线条绘制函数(如imageline()和imagepolygon())在使用特殊颜色IMG_COLOR_STYLED
或图像线绘制颜色时使用的样式IMG_COLOR_STYLEDBRUSHED
。
参数
`image`
一个图像资源,由图像创建函数之一返回,如imagecreatetruecolor()。
style
一组像素颜色。 您可以使用IMG_COLOR_TRANSPARENT常量来添加透明像素。 请注意,样式不能是空数组。
返回值
成功返回TRUE或失败时返回FALSE。
例子
以下示例脚本从画布的左上角到右下角绘制虚线:
示例#1 imagesetstyle()示例
<?php
header("Content-type: image/jpeg");
$im = imagecreatetruecolor(100, 100);
$w = imagecolorallocate($im, 255, 255, 255);
$red = imagecolorallocate($im, 255, 0, 0);
/* Draw a dashed line, 5 red pixels, 5 white pixels */
$style = array($red, $red, $red, $red, $red, $w, $w, $w, $w, $w);
imagesetstyle($im, $style);
imageline($im, 0, 0, 100, 100, IMG_COLOR_STYLED);
/* Draw a line of happy faces using imagesetbrush() with imagesetstyle */
$style = array($w, $w, $w, $w, $w, $w, $w, $w, $w, $w, $w, $w, $red);
imagesetstyle($im, $style);
$brush = imagecreatefrompng("http://www.libpng.org/pub/png/images/smile.happy.png");
$w2 = imagecolorallocate($brush, 255, 255, 255);
imagecolortransparent($brush, $w2);
imagesetbrush($im, $brush);
imageline($im, 100, 0, 0, 100, IMG_COLOR_STYLEDBRUSHED);
imagejpeg($im);
imagedestroy($im);
?>
上面的例子会输出类似于:

扩展内容
- imagesetbrush() - 设置画线的画笔图像
- imageline() - 绘制一条线
← imagesetpixel
imagesetthickness →
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com