Friday, October 24, 2025
HomeLanguagesPHP | ImagickPixelIterator getIteratorRow() function

PHP | ImagickPixelIterator getIteratorRow() function

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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS