PHP | GmagickPixel setcolorvalue() Function
Last Updated :
31 Jan, 2020
The GmagickPixel::setcolorvalue() function is an inbuilt function in PHP which is used to set the normalized value of the provided color channel for a given GmagickPixel’s color. The normalized value is a floating-point number between 0 and 1.
Syntax:
GmagickPixel GmagickPixel::setcolorvalue( int $color, float $value )
Parameters: This function accepts two parameters as mentioned above and described below:
- $color: It specifies an integer which corresponds to one of COLOR constants.
List of all COLOR constants are given below:
- imagick::COLOR_BLACK (11)
- imagick::COLOR_BLUE (12)
- imagick::COLOR_CYAN (13)
- imagick::COLOR_GREEN (14)
- imagick::COLOR_RED (15)
- imagick::COLOR_YELLOW (16)
- imagick::COLOR_MAGENTA (17)
- imagick::COLOR_OPACITY (18)
- imagick::COLOR_ALPHA (19)
- imagick::COLOR_FUZZ (20)
- $value: It specifies the value.
Return Value: This function returns GmagickPixel object on success.
Exceptions: This function throws GmagickPixelException on error.
Below given programs illustrate the GmagickPixel::setcolorvalue() function in PHP:
Program 1:
php
<?php
$imagickPixel = new GmagickPixel();
$imagickPixel ->setColorValue(gmagick::COLOR_RED, 0.8);
$colorValue = $imagickPixel ->getcolorvalue(gmagick::COLOR_RED);
echo $colorValue ;
?>
|
Output:
0.8
Used Image:
Program 2:
php
<?php
$imagickPixel = new GmagickPixel();
$gmagick = new Gmagick( 'geeksforgeeks.png' );
$gmagickPixel = new GmagickPixel();
$gmagickPixel ->setcolor( 'red' );
$gmagickPixel ->setcolorvalue(gmagick::COLOR_RED, 0.5);
$draw = new GmagickDraw();
$draw ->setfillcolor( $gmagickPixel );
$draw ->setfontsize(40);
$draw ->annotate(180, 180, 'GeeksforGeeks' );
$gmagick ->drawImage( $draw );
header( "Content-Type: image/png" );
echo $gmagick ->getImageBlob();
?>
|
Output:
Reference: https://www.php.net/manual/en/gmagickpixel.setcolorvalue.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...