PHP | ImagickPixelIterator getIteratorRow() function
Last Updated :
02 Jan, 2020
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
<?php
// Create a new imagick object
$imagick = new Imagick(
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png');
// 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
<?php
// Create a new imagick object
$imagick = new Imagick(
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png');
// 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
<?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
Explore
Basics
Array
OOPs & Interfaces
MySQL Database
PHP Advance