PHP | imagesetbrush() function
Last Updated :
14 Feb, 2020
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
$image1 = imagecreatefrompng(
$image2 = imagecreatetruecolor(700, 200);
$pink = imagecolorallocate( $image2 , 255, 0, 255);
imagefilledrectangle( $image2 , 0, 0, 800, 299, $pink );
imagesetbrush( $image2 , $image1 );
imageline( $image2 , 350, 100, 50, 6, IMG_COLOR_BRUSHED);
header( 'Content-type: image/png' );
imagepng( $image2 );
?>
|
Output:
Program 2:
<?php
$image = imagecreatefrompng(
$brush = imagecreatetruecolor(3, 3);
$brush_color = imagecolorallocate( $brush , 255, 0, 0);
imagefill( $brush , 0, 0, $brush_color );
imagesetbrush( $image , $brush );
imageline( $image , 150, 100, 500, 6, IMG_COLOR_BRUSHED);
header( 'Content-type: image/png' );
imagepng( $image );
?>
|
Output:
Reference: https://www.php.net/manual/en/function.imagesetbrush.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...