Thursday, January 22, 2026
HomeLanguagesPHP | ImagickPixelIterator getNextIteratorRow() Function

PHP | ImagickPixelIterator getNextIteratorRow() Function

The ImagickPixelIterator::getNextIteratorRow() function is an inbuilt function in PHP which is used to get the next row as an array of pixel wands from the pixel iterator.

Syntax:

array ImagickPixelIterator::getNextIteratorRow( void )

Parameters:This function doesn’t accepts any parameter.

Return Value: This function returns an array value containing the ImagickPixel objects.

Below programs illustrate the ImagickPixelIterator::getNextIteratorRow() function in PHP:

Program 1:




<?php
  
// Create a new imagick object
$imagick = new Imagick();
  
// Create a image on imagick object
// with 10x10 pixels
$imagick->newImage(10, 10, 'black');
  
// Get the pixel iterator
$imageIterator = $imagick->getPixelIterator();
  
// Rows counter variable
$rows = 0;
  
// Count the number of rows
while ($pixels = $imageIterator->getNextIteratorRow()) {
    $rows++;
}
  
echo 'The number of rows are ' . $rows;
?>


Output:

The number of rows are 10

Program 2:




<?php
  
// Create a new imagick object
$imagick = new Imagick();
  
// Create a image on imagick object
$imagick->newImage(800, 250, 'black');
  
// Get the pixel iterator
$imageIterator = $imagick->getPixelIterator();
  
while ($pixels = $imageIterator->getNextIteratorRow()) {
    foreach ($pixels as $column => $pixel) {
        if ($column % 20) {
  
            // Paint every 20th pixel black in each row
            $pixel->setColor("white");
        }
    }
  
    // Sync the iterator
    $imageIterator->syncIterator();
}
  
// Show the output
$imagick->setImageFormat('png');
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>


Output:

Reference: https://www.php.net/manual/en/imagickpixeliterator.getnextiteratorrow.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
32475 POSTS0 COMMENTS
Milvus
119 POSTS0 COMMENTS
Nango Kala
6847 POSTS0 COMMENTS
Nicole Veronica
11977 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12064 POSTS0 COMMENTS
Shaida Kate Naidoo
6986 POSTS0 COMMENTS
Ted Musemwa
7220 POSTS0 COMMENTS
Thapelo Manthata
6933 POSTS0 COMMENTS
Umr Jansen
6912 POSTS0 COMMENTS