PHP | ImagickPixel getIndex() function
Last Updated :
23 Jan, 2020
The ImagickPixel::getIndex() function is an inbuilt function in PHP which is used to get the colormap index of the pixel.
Syntax:
int ImagickPixel::getIndex( void )
Parameters:This function doesn’t accept any parameter.
Return Value: This function returns an integer value containing the index.
Exceptions: This function throws ImagickException on error.
Below given programs illustrate the ImagickPixel::getIndex() function in PHP:
Program 1 (Get the index of a single pixel):
<?php
$imagickPixel = new ImagickPixel();
$index = $imagickPixel ->getIndex();
echo $index ;
?>
|
Output:
0 // which is the default index for a pixel.
Program 2 (Get the index for all the pixels of a image):
<?php
$imagickPixel = new ImagickPixel();
$imagickPixel ->setIndex(5);
$index = $imagickPixel ->getIndex();
echo $index ;
?>
|
Output:
5
Program 3:
<?php
$imagick = new Imagick(
$imageIterator = $imagick ->getPixelIterator();
foreach ( $imageIterator as $row => $pixels ) {
foreach ( $pixels as $column => $pixel ) {
echo $pixel ->getindex() . '<br>' ;
}
$imageIterator ->syncIterator();
}
?>
|
Output:
0
0
0
0
.
.
.
Reference: https://www.php.net/manual/en/imagickpixel.getindex.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...