(PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8)
imagesetbrush —Set the brush image for line drawing
imagesetbrush() sets the brush image to be used by all line drawing functions (such asimageline() andimagepolygon()) when drawing with the special colorsIMG_COLOR_BRUSHED
orIMG_COLOR_STYLEDBRUSHED
.
You need not take special action when you are finished with a brush, but if you destroy the brush image (or let PHP destroy it), you must not use theIMG_COLOR_BRUSHED
orIMG_COLOR_STYLEDBRUSHED
colors until you have set a new brush image!
image
AGdImage object, returned by one of the image creation functions,such asimagecreatetruecolor().
brush
An image object.
Version | Description |
---|---|
8.0.0 | image andbrush expectGdImage instances now; previously,resources were expected. |
Example #1imagesetbrush() example
<?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);
?>
The above example will outputsomething similar to:
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.