The imagesetbrush() function is an inbuilt function in PHP which is used to set the brush image for line drawing. Line drawing is done using functions like imageline() or imagepolygon(). Special colors can be drawn using IMG_COLOR_BRUSHED or IMG_COLOR_STYLEDBRUSHED.
Syntax:
bool imagesetbrush( resource $image, resource $brush )
Parameters:This function accepts two parameters as mentioned above and described below:
- $image: It specifies the image resource to work on.
- $brush: It specifies another image resource acting as brush.
Return Value: This function returns TRUE on success or FALSE on failure.
Below given programs illustrate the imagesetbrush() function in PHP:
Program 1:
<?php // Load the png image $image1 = imagecreatefrompng( // Create a another image, 700x200 to be used as brush $image2 = imagecreatetruecolor(700, 200); // Fill the background $pink = imagecolorallocate( $image2 , 255, 0, 255); imagefilledrectangle( $image2 , 0, 0, 800, 299, $pink ); // Set the brush imagesetbrush( $image2 , $image1 ); // Draw line imageline( $image2 , 350, 100, 50, 6, IMG_COLOR_BRUSHED); // Output image to the browser header( 'Content-type: image/png' ); imagepng( $image2 ); ?> |
Output:
Program 2:
<?php // Load the png image $image = imagecreatefrompng( // Create a red color brush of size 3 $brush = imagecreatetruecolor(3, 3); $brush_color = imagecolorallocate( $brush , 255, 0, 0); imagefill( $brush , 0, 0, $brush_color ); // Set the brush imagesetbrush( $image , $brush ); // Draw line with brush imageline( $image , 150, 100, 500, 6, IMG_COLOR_BRUSHED); // Output image to the browser header( 'Content-type: image/png' ); imagepng( $image ); ?> |
Output:
Reference: https://www.php.net/manual/en/function.imagesetbrush.php