PHP | GmagickPixel setcolor() function
The GmagickPixel::setcolor() function is an inbuilt function in PHP which is used to set the color of the GmagickPixel object.
Syntax:
GmagickPixel GmagickPixel::setcolor( string $color )
Parameters:This function accepts a single parameter $color which holds the color.
Return Value: This function returns GmagickPixel object on success.
Exceptions: This function throws GmagickPixelException on error.
Below given programs illustrate the GmagickPixel::setcolor() function in PHP:
Program 1:
<?php
$gmagickPixel = new GmagickPixel();
$gmagickPixel ->setColor( '#428554' );
$color = $gmagickPixel ->getColor();
print ( "<pre>" .print_r( $color , true). "</pre>" );
?>
|
Output:
rgb(16962, 34181, 21588)
Program 2:
<?php
$gmagick = new Gmagick( 'geeksforgeeks.png' );
$gmagickPixel = new GmagickPixel();
$gmagickPixel ->setcolor( 'blue' );
$draw = new GmagickDraw();
$draw ->setfillcolor( $gmagickPixel );
$draw ->setfontsize(40);
$draw ->annotate(50, 180, 'GeeksforGeeks' );
$gmagick ->drawImage( $draw );
header( "Content-Type: image/png" );
echo $gmagick ->getImageBlob();
?>
|
Output:
Reference: https://www.php.net/manual/en/gmagickpixel.setcolor.php
Last Updated :
23 Jan, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...