导航首页 » 技术教程 » PHP:imagesetstyle()的用法_GD库图像处理函数
PHP:imagesetstyle()的用法_GD库图像处理函数 136 2023-12-15   

imagesetstyle

(PHP 4 >= 4.0.6, PHP 5)

imagesetstyle — 设定画线的风格

说明

bool imagesetstyle ( resource $image , array $style )

imagesetstyle() 设定所有画线的函数(例如 imageline() 和 imagepolygon())在使用特殊颜色 IMG_COLOR_STYLED 或者用 IMG_COLOR_STYLEDBRUSHED 画一行图像时所使用的风格。

参数

image

由图象创建函数(例如imagecreatetruecolor())返回的图象资源。

style

像素组成的数组。你可以通过常量 IMG_COLOR_TRANSPARENT 来添加一个透明像素。

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

范例

下面的示例脚本在画布上从左上角到右下角画一行虚线:

Example #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);
?>

以上例程的输出类似于:

参见

imagesetbrush() - 设定画线用的画笔图像 imageline() - 画一条线段


!!!站长长期在线接!!!

网站、小程序:定制开发/二次开发/仿制开发等

各种疑难杂症解决/定制接口/定制采集等

站长微信:lxwl520520

站长QQ:1737366103