PHP | ImagickPixel setColorValue() function
Last Updated :
02 Jan, 2020
The ImagickPixel::setColorValue() function is an inbuilt function in PHP which is used to set the normalized value of the provided color channel for a given ImagickPixel’s color. The normalized value is a floating-point number between 0 and 1.
Syntax:
bool ImagickPixel::setColorValue( int $color, float $value )
Parameters:This function accepts two parameters as mentioned above and described below:
- $color: It specifies the 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 to be set.
Return Value: This function returns TRUE on success.
Exceptions: This function throws ImagickException on error.
Below given programs illustrate the ImagickPixel::setColorValue() function in PHP:
Program 1:
<?php
$imagickPixel = new ImagickPixel();
$imagickPixel ->setColorValue(imagick::COLOR_RED, 0.8);
$colorValue = $imagickPixel ->getColorValue(imagick::COLOR_RED);
echo $colorValue ;
?>
|
Output:
0.8
Program 2:
<?php
$imagick = new Imagick(
$imageIterator = $imagick ->getPixelIterator();
foreach ( $imageIterator as $row => $pixels ) {
if ( $row % 5) {
foreach ( $pixels as $column => $pixel ) {
if ( $column % 1000) {
$pixel ->setColor( "green" );
$pixel ->setColorValue(Imagick::COLOR_ALPHA, 0);
}
}
}
$imageIterator ->syncIterator();
}
header( "Content-Type: image/jpg" );
echo $imagick ;
?>
|
Output:
Reference: https://www.php.net/manual/en/imagickpixel.setcolorvalue.php
Share your thoughts in the comments
Please Login to comment...