Thursday, June 18, 2026
HomeLanguagesPHP | Imagick setFirstIterator() function

PHP | Imagick setFirstIterator() function

The Imagick::setFirstIterator() function is an inbuilt function in PHP which is used to set the Imagick iterator to the first image.

Syntax:

bool Imagick::setFirstIterator( void )

Parameters: This function doesn’t accept any parameter.

Return Value: This function returns TRUE on success.

Exceptions: This function throws ImagickException on error.

Below given programs illustrate the Imagick::setFirstIterator() function in PHP:

Program 1:




<?php
   
// Create a new imagick object
$imagick = new Imagick(
   
// Add a new image to same object, this
// will automatically move index to new
// image which is added.
$imagick->addImage(new Imagick(
   
echo 'Index before setFirstIterator(); is '
    . $imagick->getIteratorIndex() 
    .'<br>';
   
// Set the Imagick iterator to the first image
$imagick->setFirstIterator();
   
echo 'Index after setFirstIterator(); is ' 
    . $imagick->getIteratorIndex() 
    .'<br>';
?>


Output:

Index before setFirstIterator(); is 1
Index after setFirstIterator(); is 0

Program 2:




<?php
// Create a new imagick object
$imagick = new Imagick();
   
// Array of images
$images = [
];
   
// Read the images
$imagick->readImages($images);
  
echo 'Index before setFirstIterator(); is ' 
    . $imagick->getIteratorIndex() 
    . '<br>';
  
// Set the Imagick iterator to the first image
$imagick->setFirstIterator();
  
echo 'Index after setFirstIterator(); is ' 
    . $imagick->getIteratorIndex() 
    . '<br>';
?>


Output:

Index before setFirstIterator(); is 2
Index after setFirstIterator(); is 0

Reference: https://www.php.net/manual/en/imagick.setfirstiterator.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
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
6965 POSTS0 COMMENTS