Thursday, September 25, 2025
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
32319 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6681 POSTS0 COMMENTS
Nicole Veronica
11854 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11910 POSTS0 COMMENTS
Shaida Kate Naidoo
6794 POSTS0 COMMENTS
Ted Musemwa
7070 POSTS0 COMMENTS
Thapelo Manthata
6753 POSTS0 COMMENTS
Umr Jansen
6761 POSTS0 COMMENTS