Wednesday, June 17, 2026
HomeLanguagesPHP | ImagickPixelIterator getCurrentIteratorRow() function

PHP | ImagickPixelIterator getCurrentIteratorRow() function

The ImagickPixelIterator::getCurrentIteratorRow() function is an inbuilt function in PHP which is used to get the current row as an array of ImagickPixel objects from the pixel iterator.

Syntax:

array ImagickPixelIterator::getCurrentIteratorRow( void )

Parameters:This function doesn’t accept any parameter.

Return Value: This function returns an array value containing the ImagickPixel objects that can themselves be iterated.

Exceptions: This function throws ImagickException on error.

Below given programs illustrate the ImagickPixelIterator::getCurrentIteratorRow() function in PHP:

Program 1 (Get first five pixels of first row):




<?php
// Create a new imagick object
$imagick = new Imagick();
   
// Create a image on imagick object with 
// 5 pixels on row and 10 pixels on columns
$imagick->newImage(5, 10, 'black');
  
// Get the pixel iterator
$pixelIterator = $imagick->getPixelIterator();
  
// Get the current iterator row
$row = $pixelIterator->getCurrentIteratorRow();
print("<pre>".print_r($row, true)."</pre>");
?>


Output:

Array
(
    [0] => ImagickPixel Object
        (
        )

    [1] => ImagickPixel Object
        (
        )

    [2] => ImagickPixel Object
        (
        )

    [3] => ImagickPixel Object
        (
        )

    [4] => ImagickPixel Object
        (
        )

)

Program 2 (Get the color of first five pixels of first row):




<?php
// Create a new imagick object
$imagick = new Imagick(
  
// Get the pixel iterator
$pixelIterator = $imagick->getPixelIterator();
  
// Get the current iterator row
$row = $pixelIterator->getCurrentIteratorRow();
echo "First five colors of pixels are:<br>";
print("Pixel 1:" . "<pre>".print_r($row[0]->getColor(), true)."</pre>");
print("Pixel 2:" . "<pre>".print_r($row[1]->getColor(), true)."</pre>");
print("Pixel 3:" . "<pre>".print_r($row[2]->getColor(), true)."</pre>");
print("Pixel 4:" . "<pre>".print_r($row[3]->getColor(), true)."</pre>");
print("Pixel 5:" . "<pre>".print_r($row[4]->getColor(), true)."</pre>");
?>


Output:

First five colors of pixels are:
Pixel 1:
Array
(
    [r] => 255
    [g] => 255
    [b] => 255
    [a] => 1
)
Pixel 2:
Array
(
    [r] => 255
    [g] => 255
    [b] => 255
    [a] => 1
)
Pixel 3:
Array
(
    [r] => 255
    [g] => 255
    [b] => 255
    [a] => 1
)
Pixel 4:
Array
(
    [r] => 255
    [g] => 255
    [b] => 255
    [a] => 1
)
Pixel 5:
Array
(
    [r] => 255
    [g] => 255
    [b] => 255
    [a] => 1
)

Reference: https://www.php.net/manual/en/imagickpixeliterator.getcurrentiteratorrow.php

RELATED ARTICLES

Most Popular

Dominic
32516 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6898 POSTS0 COMMENTS
Nicole Veronica
12014 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS