PHP | ImagickPixel setIndex() Function
Last Updated :
14 Jan, 2020
The ImagickPixel::setIndex() function is an inbuilt function in PHP which is used to set the colormap index of the pixel.
Syntax:
bool ImagickPixel::setIndex( int $index )
Parameters: This function accepts a single parameter $index which holds the index to be set.
Return Value: This function returns TRUE on success.
Below programs illustrate the ImagickPixel::setIndex() function in PHP:
Program 1: This program set and return the index for a single pixel.
<?php
$imagickPixel = new ImagickPixel();
$imagickPixel ->setIndex(15);
$index = $imagickPixel ->getIndex();
echo $index ;
?>
|
Output:
15
Program 2: This program returns the index value of an image.
<?php
$imagick = new Imagick(
$imageIterator = $imagick ->getPixelIterator();
$i = 0;
foreach ( $imageIterator as $row => $pixels ) {
foreach ( $pixels as $column => $pixel ) {
$pixel ->setIndex( $i );
echo $pixel ->getIndex() . '<br>' ;
$i ++;
}
$imageIterator ->syncIterator();
}
?>
|
Output:
0
1
2
3
.
.
.
Reference: https://www.php.net/manual/en/imagickpixel.setindex.php
Share your thoughts in the comments
Please Login to comment...