Thursday, May 21, 2026
HomeLanguagesPHP | Imagick setLastIterator() Function

PHP | Imagick setLastIterator() Function

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

Syntax:

bool Imagick::setLastIterator( void )

Parameters: This function doesn’t accepts any parameter.

Return Value: This function returns TRUE on success.

Exceptions: This function throws ImagickException on error.

Below programs illustrate the Imagick::setLastIterator() 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(
  
// Move the cursor to first image
$imagick->setFirstIterator();
  
echo 'Index before setLastIterator() is '
          . $imagick->getIteratorIndex() . '<br>';
  
// Set the Imagick iterator to the last image
$imagick->setLastIterator();
  
echo 'Index after setLastIterator() is '
         . $imagick->getIteratorIndex() . '<br>';
?>


Output:

Index before setLastIterator() is 0
Index after setLastIterator() is 1

Program 2:




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


Output:

Index before setLastIterator() is 0
Index after setLastIterator() is 4

Reference: https://www.php.net/manual/en/imagick.setlastiterator.php

RELATED ARTICLES

Most Popular

Dominic
32514 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6892 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12107 POSTS0 COMMENTS
Shaida Kate Naidoo
7016 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6975 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS