array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.imagesetstyle.php', 1 => 'imagesetstyle', ), 'up' => array ( 0 => 'ref.image.php', 1 => 'GD 和图像处理 函数', ), 'prev' => array ( 0 => 'function.imagesetpixel.php', 1 => 'imagesetpixel', ), 'next' => array ( 0 => 'function.imagesetthickness.php', 1 => 'imagesetthickness', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/image/functions/imagesetstyle.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8)
imagesetstyle — 设定线条的样式
imagesetstyle() 设定所有线条函数(例如 imageline()
和 imagepolygon())在使用特殊颜色 IMG_COLOR_STYLED
或者颜色为 IMG_COLOR_STYLEDBRUSHED
绘制图像线条的样式。
image
由图象创建函数(例如imagecreatetruecolor())返回的 GdImage 对象。
style
像素颜色组成的数组。可以通过常量 IMG_COLOR_TRANSPARENT
来添加透明像素。注意
style
不能是空 array。
下面的示例脚本在画布上从左上角到右下角画一行虚线:
示例 #1 imagesetstyle() 例子
<?php
header("Content-type: image/jpeg");
$im = imagecreatetruecolor(100, 100);
$w = imagecolorallocate($im, 255, 255, 255);
$red = imagecolorallocate($im, 255, 0, 0);
/* 画一条虚线,5 个红色像素,5 个白色像素 */
$style = array($red, $red, $red, $red, $red, $w, $w, $w, $w, $w);
imagesetstyle($im, $style);
imageline($im, 0, 0, 100, 100, IMG_COLOR_STYLED);
/* 用 imagesetbrush() 和 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);
?>
以上示例的输出类似于: