PHP 8.3.4 Released!

imagesetbrush

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

imagesetbrush为线条设置笔刷图像

说明

imagesetbrush(GdImage $image, GdImage $brush): bool

当用特殊的颜色 IMG_COLOR_BRUSHEDIMG_COLOR_STYLEDBRUSHED 绘制时,imagesetbrush() 通过所有的线条函数设置要使用的笔刷图像。【注:使用笔刷图像,所画的线是由 brush 所代表的图像构成的。请参考并尝试运行 imagesetstyle() 中的例子以帮助理解。】

警告

笔刷完成后不需要采取什么特殊动作,但如果要销毁笔刷图像(或让 PHP 销毁),不能使用 IMG_COLOR_BRUSHEDIMG_COLOR_STYLEDBRUSHED 颜色,除非设置了新的笔刷图像。

参数

image

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

brush

图像对象。

返回值

成功时返回 true, 或者在失败时返回 false

更新日志

版本 说明
8.0.0 imagebrush 现在需要 GdImage 实例,之前需要 resource

示例

示例 #1 imagesetbrush() 示例

<?php
// Load a mini php logo
$php = imagecreatefrompng('./php.png');

// Create the main image, 100x100
$im = imagecreatetruecolor(100, 100);

// Fill the background with white
$white = imagecolorallocate($im, 255, 255, 255);
imagefilledrectangle($im, 0, 0, 299, 99, $white);

// Set the brush
imagesetbrush($im, $php);

// Draw a couple of brushes, each overlaying each
imageline($im, 50, 50, 50, 60, IMG_COLOR_BRUSHED);

// Output image to the browser
header('Content-type: image/png');

imagepng($im);
imagedestroy($im);
imagedestroy($php);
?>

以上示例的输出类似于:

Output of example : imagesetbrush()

add a note

User Contributed Notes 1 note

up
0
brent at ebrent dot net
17 years ago
Use a brush to create a thick line.

To create a 3x3 red brush:

<?php
$brush_size
= 3;
$brush = imagecreatetruecolor($brush_size,$brush_size);
$brush_color = imagecolorallocate($brush,255,0,0);
imagefill($brush,0,0,$brush_color);
imagesetbrush($im,$brush);
?>

Then use imageline() or imagepolygon() with IMG_COLOR_BRUSHED as the color.

To stop using the brush, destroy it:

<?php imagedestroy($brush); ?>

The brush can also be created from an existing image.
To Top