Friday, October 10, 2025
HomeLanguagesPHP | ImagickPixelIterator setIteratorFirstRow() Function

PHP | ImagickPixelIterator setIteratorFirstRow() Function

The ImagickPixelIterator::setIteratorFirstRow() function is an inbuilt function in PHP which is used to set the pixel iterator to the first pixel row.

Syntax:

bool ImagickPixelIterator::setIteratorFirstRow( void )

Parameters: This function doesn’t accepts any parameter.

Return Value: This function returns TRUE on success.

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

Program 1:




<?php
  
// Create a new imagick object
$imagick = new Imagick(
    
// Get the pixel iterator
$pixelIterator = $imagick->getPixelIterator();
    
// Set the pixel iterator to 50
$pixelIterator->setIteratorRow(50);
   
// Get the current iterator row
echo "Current row is " . $pixelIterator->getIteratorRow();
   
// Set the iterator to first row
$pixelIterator->setIteratorFirstRow();
   
// Get the current iterator row
echo "<br>Current row is " . $pixelIterator->getIteratorRow();
?>


Output:

Current row is 50
Current row is 0

Program 2:




<?php
  
// Create a new imagick object
$imagick = new Imagick(
   
// Get the pixel iterator
$pixelIterator = $imagick->getPixelIterator();
  
$pixelIterator->setIteratorRow(40);
   
// Get the current iterator row
$row = $pixelIterator->getCurrentIteratorRow();
echo "Colors of 61th and 62nd pixel from 40th row are:<br>";
print("Pixel 60:" . "<pre>".print_r($row[60]->getColor(), true)."</pre>");
print("Pixel 61:" . "<pre>".print_r($row[61]->getColor(), true)."</pre>");
  
// Set the iterator to first row
$pixelIterator->setIteratorFirstRow();
  
// Get the current iterator row
$row = $pixelIterator->getCurrentIteratorRow();
echo "First two colors of pixels from first row are:<br>";
print("Pixel 1:" . "<pre>".print_r($row[0]->getColor(), true)."</pre>");
print("Pixel 2:" . "<pre>".print_r($row[1]->getColor(), true)."</pre>");
?>


Output:

Colors of 61th and 62nd pixel from 40th row are:
Pixel 60:
Array
(
    [r] => 110
    [g] => 199
    [b] => 131
    [a] => 1
)
Pixel 61:
Array
(
    [r] => 23
    [g] => 165
    [b] => 57
    [a] => 1
)
First two colors of pixels from first row are:
Pixel 1:
Array
(
    [r] => 255
    [g] => 255
    [b] => 255
    [a] => 1
)
Pixel 2:
Array
(
    [r] => 255
    [g] => 255
    [b] => 255
    [a] => 1
)

Reference: https://www.php.net/manual/en/imagickpixeliterator.setiteratorfirstrow.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
32350 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6718 POSTS0 COMMENTS
Nicole Veronica
11880 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6838 POSTS0 COMMENTS
Ted Musemwa
7101 POSTS0 COMMENTS
Thapelo Manthata
6794 POSTS0 COMMENTS
Umr Jansen
6794 POSTS0 COMMENTS