PHP | ImagickPixel setColor() function
Last Updated :
02 Jan, 2020
The ImagickPixel::setColor() function is an inbuilt function in PHP which is used to set the color of the ImagickPixel object.
Syntax:
bool ImagickPixel::setColor( string $color )
Parameters:This function accepts a single parameter $color which holds the color.
Return Value: This function returns TRUE on success.
Exceptions: This function throws ImagickException on error.
Below given programs illustrate the ImagickPixel::setColor() function in PHP:
Program 1:
<?php
$imagickPixel = new ImagickPixel();
$imagickPixel ->setColor( '#428554' );
$color = $imagickPixel ->getColor();
print ( "<pre>" .print_r( $color , true). "</pre>" );
?>
|
Output:
Array
(
[r] => 66
[g] => 133
[b] => 84
[a] => 1
)
Program 2:
<?php
$imagick = new Imagick(
$imageIterator = $imagick ->getPixelIterator();
foreach ( $imageIterator as $row => $pixels ) {
if ( $row % 5) {
foreach ( $pixels as $column => $pixel ) {
if ( $column % 5) {
$pixel ->setColor( "green" );
}
}
}
$imageIterator ->syncIterator();
}
header( "Content-Type: image/jpg" );
echo $imagick ;
?>
|
Output:
Reference: https://www.php.net/manual/en/imagickpixel.setcolor.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...