imagesetstyle() 设定所有画线的函数(例如 imageline() 和 imagepolygon())在使用特殊颜色 IMG_COLOR_STYLED 或者用 IMG_COLOR_STYLEDBRUSHED 画一行图像时所使用的风格。如果成功则返回 TRUE ,失败则返回 FALSE 。
语法:
bool imagesetstyle( resource image, array style )
style 参数是像素组成的数组。
imageline() 函数配合 imagesetstyle() 可以画一条虚线段:
<?php
header("Content-type: image/png");
$im = @imagecreate(300, 50)or die("创建图像资源失败");
$bg = imagecolorallocate($im, 204, 204, 204);
$red = imagecolorallocate($im, 255, 0, 0);
// 画一条虚线,5 个红色像素,4 个背景像素
$style = array($red, $red, $red, $red, $red, $bg, $bg, $bg, $bg);
imagesetstyle($im, $style);
imageline($im, 0, 20, 200, 20, IMG_COLOR_STYLED);
imagepng($im);
imagedestroy($im);
?>