首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

imagesetstyle

(PHP 4 >= 4.0.6, PHP 5, PHP 7)

imagesetstyle - 设置线条绘制的样式

描述

代码语言:javascript
复制
bool imagesetstyle ( resource $image , array $style )

imagesetstyle()设置所有线条绘制函数(如imageline()和imagepolygon())在使用特殊颜色IMG_COLOR_STYLED或图像线绘制颜色时使用的样式IMG_COLOR_STYLEDBRUSHED

参数

代码语言:txt
复制
`image`   

一个图像资源,由图像创建函数之一返回,如imagecreatetruecolor()。

style

一组像素颜色。 您可以使用IMG_COLOR_TRANSPARENT常量来添加透明像素。 请注意,样式不能是空数组。

返回值

成功返回TRUE或失败时返回FALSE。

例子

以下示例脚本从画布的左上角到右下角绘制虚线:

示例#1 imagesetstyle()示例

代码语言:javascript
复制
<?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 →

扫码关注腾讯云开发者

领取腾讯云代金券