The ImagickPixelIterator::getIteratorRow() function is an inbuilt function in PHP which is used to get the current pixel iterator row. This function is used to check in which row we are currently at while traversing the pixels of an image.
Syntax:
int ImagickPixelIterator::getIteratorRow( void )
Parameters:This function doesn’t accept any parameter.
Return Value: This function returns an integer value containing the current pixel iterator row.
Exceptions: This function throws ImagickException on error.
Below given programs illustrate the ImagickPixelIterator::getIteratorRow() function in PHP:
Program 1:
<?php // Create a new imagick object $imagick = new Imagick( // Get the pixel iterator $pixelIterator = $imagick ->getPixelIterator(); // Get the current iterator row echo "Current row is " . $pixelIterator ->getIteratorRow(); ?> |
Output:
Current row is 0 // which is the default row from where we start
Program 2:
<?php // Create a new imagick object $imagick = new Imagick( // Get the pixel iterator $pixelIterator = $imagick ->getPixelIterator(); // Set the pixel iterator to 30 $pixelIterator ->setIteratorRow(30); // Get the current iterator row echo "Current row is " . $pixelIterator ->getIteratorRow(); ?> |
Output:
Current row is 30
Program 3:
<?php // Create a new imagick object $imagick = new Imagick(); // Create a image on imagick object with size of 10x10 pixels $imagick ->newImage(10, 10, 'black' ); // Get the pixel iterator $imageIterator = $imagick ->getPixelIterator(); // Loop through pixel rows foreach ( $imageIterator as $row => $pixels ) { // Get the current iterator row echo "Current row is " . $imageIterator ->getIteratorRow() . '<br>' ; } ?> |
Output:
Current row is 0 Current row is 1 Current row is 2 Current row is 3 Current row is 4 Current row is 5 Current row is 6 Current row is 7 Current row is 8 Current row is 9
Reference: https://www.php.net/manual/en/imagickpixeliterator.getiteratorrow.php